News for hackers. Stuff that matters.
Re:MangaDex infrastructure overview by maxk42 on Tuesday September 07, 2021 @05:17AM (#28442679)
My approach to what?
Re:MangaDex infrastructure overview by maxk42 on Tuesday September 07, 2021 @06:36AM (#28443113)
(1) Simple beats complex.

(2) You can spend weeks building complex infrastructure or caching systems only to find out that some fixed C in your equation was larger than your overhead savings. In other words: Measure everything. In other other words: Premature optimization is the root of all evil.

(3) Fewer moving parts equals less overhead. (Again: Simple beats complex.) It also makes things simpler to reason about. If you can get by without the fancy frameworks, VMs, containers, ORM, message queues, etc. you'll probably have a more performant system. You need to understand what each of those things does and how and why you're using them. Which brings me to:

(4) Learn your tools. You can push an incredible amount of performance out of MySQL, for instance, if you learn to adjust its settings, benchmark different DB engines for your application, test different approaches to building your schemas, test different queries, make use of tools like the EXPLAIN statement, etc. you'll probably never need to do something silly like make half a dozen round-trips to the database in a single page load.

(5) Understand your data. Reason about the data you will need before you build your application. If you're working with an existing application, make sure you are very familiar with your application's database schema. Reason ahead of time about what requirements you have or will have, and which data will be needed simultaneously for different operations. Design your database tables in such a way as to minimize the number of round-trips you will need to make to the database. (My rule of thumb: Try to do everything in a single request per page, if possible. Two is acceptable. Three is the maximum. If I need to make more than three round-trips to the database in a single page request, I'm either doing something too complex or I seriously need to rethink my schema.)

(6) Networking is slow. Minimize network traversal. Avoid relying on third-party APIs where possible when performance counts. Prefer running small databases local to the web server to large databases that require network traversal to reach. This is how I handled 30 billion writes / day: 12 web servers with separate MySQL instances local to each sharded on primary key IDs. The servers continuously exported data to an "aggregation" server, which was subsequently copied to another server for additional processing. Having the web server and database local to the same VM meant they didn't need to wait for any network traversal to record their data. I could've easily needed several times as many servers if I had gone with a traditional cluster due to the additional latency. When you need to process 25,000 events in a second, every millisecond counts.

(7) Static files beat the hell out of databases for read-only performance. (Generally.)

(8) Sometimes you can get things moving even faster by storing it in memory instead of on disk.

(9) Reiterating what's in (3): Most web frameworks are garbage when it comes to performance. If your framework isn't in the top half of the Techempower benchmarks, (or higher for performance-critical applications) it's probably going to be better for performance to write your own code if you understand what you're doing. Link for reference: https://www.techempower.com/benchmarks/ Note that the Techempower benchmarks themselves can be misleading. Many of the best performers are only there because of some built-in caching, obscure language hack, or standards-breaking corner-cutting. But for the frameworks that aren't doing those things, the benchmark is solid. Again, make sure you know your tools and why the benchmark rating is what it is. Note also that some entire languages don't really show up in the top half of techempower benchmarks. Take that into consideration if performance is critical to your application.

(10) Most applications don't need great performance. Remember that a million hits a day is really just 12 hits per second. Of course the reality is that the traffic doesn't come in evenly across every second of the day, but the point remains: Most applications just don't need that much optimization. Just stick with (1) and (2) if you're not serving a hundred million hits per day and you'll be fine.

Re:MangaDex infrastructure overview by arethuza on Tuesday September 07, 2021 @08:57AM (#28444149)
"Simple beats complex."

In the very first lecture of the Computer Science degree I did in the 1980s the lecturer emphasised KISS, and said that while we almost certainly wouldn't believe it at first eventually we'd realise that this is the most important design principle of all. Probably took me ~15 years... ;-)

Re:MangaDex infrastructure overview by politelemon on Tuesday September 07, 2021 @09:25AM (#28444517)
Sadly I think this is a lesson that we as an industry consistently keep unlearning.
Re:MangaDex infrastructure overview by arthur_sav on Tuesday September 07, 2021 @08:47AM (#28444047)
> Simple beats complex. > Fewer moving parts equals less overhead.

Took me almost a decade to really comprehend this.

I used to include all sorts of libraries, try out all the fancy patterns/architectures etc...

After countless of hours debugging production issues... the best code i've ever written is the one with the fewer moving parts. Easier to debug and the issues are predictable.

Re:MangaDex infrastructure overview by kiba on Tuesday September 07, 2021 @09:01AM (#28444204)
"The best part is no part." is an engineering quote I heard.
Re:MangaDex infrastructure overview by bradknowles on Tuesday September 07, 2021 @07:33PM (#28451133)
Said in a slightly different way: No part is better than no part.

I know I’m not the first to use that phrasing, but I’m not sure where I picked it up. If someone wants to point out the etymology of that type of phrase, I’d be glad to read up on what I’ve forgotten/missed.

Re:MangaDex infrastructure overview by arethuza on Tuesday September 07, 2021 @09:26AM (#28444524)
I'm sure I've heard something like "engineering is solving problems while doing as little new as possible".
Re:MangaDex infrastructure overview by emi2k01 on Wednesday September 08, 2021 @02:31AM (#28453779)
> 12 web servers with separate MySQL instances local to each sharded on primary key IDs.

I don't understand this part. Hopefully you can clarify this to me.

If you're sharding by primary key, doesn't that mean that there's a high chance that the shard in your local DB instance won't have the data the web server is requesting?

I'm not familiar with DB management.

Re:MangaDex infrastructure overview by radicalbyte on Friday September 10, 2021 @04:15PM (#28486393)
Imagine you have a system which services 50 states. In the vast majority of cases, states only look at or mutate information on their own state.

In that case, you can easily split the data between shards based on ranges of an integer key. It's very easy to code, test, deploy and understand such a design.

Re:MangaDex infrastructure overview by Folcon on Tuesday September 07, 2021 @07:31AM (#28443432)
Thanks, this is a good list in general of things to think about =)...

I've not really ever applied 9 myself, I've run comparative benchmarks a couple of times, but not thought about using that as a basis for whether to roll my own on critical performance parts.

Re:MangaDex infrastructure overview by vymague on Tuesday September 07, 2021 @08:00AM (#28443619)
> But for the frameworks that aren't doing those things, the benchmark is solid.

Any example of such frameworks?

Re:MangaDex infrastructure overview by manigandham on Tuesday September 07, 2021 @08:37AM (#28443935)
(ASP).NET is solid. Extremely fast, very reliable, and highly productive.

https://dotnet.microsoft.com/apps/aspnet

Re:MangaDex infrastructure overview by radicalbyte on Friday September 10, 2021 @04:16PM (#28486401)
As long as you know what you're doing. If you're throwing an ORM like Entity Framework at a problem because you don't understand SQL, then you're going to see poor performance.
Re:MangaDex infrastructure overview by probotect0r on Tuesday September 07, 2021 @11:08AM (#28445794)
Can you share how you do logging/monitoring/alerting for your site?
Re:MangaDex infrastructure overview by maxk42 on Tuesday September 07, 2021 @12:13PM (#28446488)
Bash scripts and cron. Automatic alerts go out to devs via OpsGenie when resource availability drops so we can get out ahead of it. 0 seconds of downtime in the past 12 months.
Re:MangaDex infrastructure overview by Folcon on Tuesday September 07, 2021 @05:45AM (#28442835)
To architecting a high traffic site =)...
Re:MangaDex infrastructure overview by Cipater on Tuesday September 07, 2021 @08:19AM (#28443772)
He posted a reply to his own comment.

https://news.ycombinator.com/item?id=28443113

Re:MangaDex infrastructure overview by maxk42 on Tuesday September 07, 2021 @12:54PM (#28447013)
Actually, my reply was to Folcon. HN simply doesn't allow you to reply to comments beyond a certain depth sometimes.

Perhaps mods have the ability to extend this for active discussions and that's why I can reply now?

Re:MangaDex infrastructure overview by detaro on Tuesday September 07, 2021 @12:55PM (#28447022)
it's timing based. you can always reply by going to the permalink of the comment you want to reply to.
Re:MangaDex infrastructure overview by maxk42 on Tuesday September 07, 2021 @12:58PM (#28447064)
Couldn't reply to this comment - but sure enough, the permalink gives me the option. Thank you for the info!
Re:MangaDex infrastructure overview by detaro on Tuesday September 07, 2021 @01:03PM (#28447130)
Yeah, it's a somewhat well-meaning feature (supposed to slow down flamewars) that is extremely unintuitive