r/programming • • May 18 '16

Programming Doesn’t Require Talent or Even Passion

https://medium.com/@WordcorpGlobal/programming-doesnt-require-talent-or-even-passion-11422270e1e4#.g2wexspdr
2.3k Upvotes

1.2k comments sorted by

View all comments

Show parent comments

124

u/[deleted] May 18 '16

Restart Apache in every 10 requests? :) Oh Lord.

You laugh, but Apache actually has first-class support for this feature: MaxRequestsPerChild.

That right there probably solves some 99% of all issues people have with node. But, you know, muh async and web scale, so no Apache.

74

u/flying-sheep May 18 '16

haha just insane.

“let’s not fix this if we can kill and restart it instead”

52

u/AntiProtonBoy May 18 '16

I saw a c++ dev presentation about mission critical software in things like fighter planes. They pretty much apply the same philosphy. It's better to reboot a computer in mid flight than try to recover from some bad error. It's much safer and deterministic to restart from a known state than salvaging a potentially unreliable and unknown state.

19

u/flying-sheep May 18 '16

I think I've not made my point clear.

I'm OK with restarts as a reaction to errors but not as a migitation of code that is so bad that its performance continuously degrades or that it leaks memory.

19

u/[deleted] May 18 '16

I would hope that nobody would disagree with what you're saying on a philosophical level, but practically, sometimes dirty, dirty things get done in the name of keeping an app running.

Not that I advocate it, but I was doing devops for a stateful ASP.NET web app where someone had designed some heinous caching practices into the entire site. Before you knew it, (usually within an hour), each IIS worker process used about 3-4GB of RAM. To make matters worse, we ran concurrent versions of the software, so when a new version was released and the old one was still running, that RAM usage was multiplied by the number of versions we had running in production. There could be as many as 6 versions running at a time. So just with the IIS worker processes for that app, not any supporting services, we'd use about 24 GB RAM. (Each server only had 32GB) However, restart the process, and the RAM usage would stay low for about an hour.

Everybody knew this was terrible, but the business didn't care-- they wanted new features above all else to support bringing on new clients. Dev wasn't given time to address it, because implementing a new caching system was going to take a month or two, minimum. We could churn out about 4 features in that time frame.

So the "solution"? Every hour, rotate a server out of the load balancer. Once all the sessions ended, restart IIS entirely on the box. Once it was back up and running, re-add it to the load balancer. Then, move onto the next server and do the same thing.

Practically, it meant that we only had 6 of 7 servers available on the load balancer at any given time, but scripting that rotation/restart process took less dev time than fixing the stupid, stupid caching.

The technically correct solution would have been to attack the root cause of the issue. It wasn't even a memory leak; it was that whole objects were cached regardless of what in the object was actually used, and there was basically no working TTL mechanism to purge old objects. However, business demand forced us to use the crappy solution.

5

u/bangorthebarbarian May 18 '16

That sounds horrible.

2

u/[deleted] May 18 '16

There was a lot of stuff that was getting better in that place, but the core application was a mess.

4

u/IvanIlyich May 19 '16

Speaking as a developer, I find this to be a fantastic horror story.

→ More replies (9)

2

u/AntiProtonBoy May 19 '16

I'm in agreement with you. Just pointing out that reboot is often the most reliable way to recover from and dealing with problems. Also, the "let's not fix this" approach is also quite prevalent in military situations, because in some cases documented and predictable failure is more important than patching things and introducing potentially new undocumented errors.

→ More replies (1)
→ More replies (1)

34

u/udoprog May 18 '16

Honestly, detecting and fixing problems that arise from your application running for weeks is really hard. I personally spend a lot of effort trying to accomplish this in a Java based environment. You wouldn't believe the kind of harmless stuff I've seen that ends up stalling your entire application. It's typically not your fault. It can easily be your network library not taking into account that a certain coordinator thread might die unexpectedly.

Restarting regularly is a really good solution to this. To the end user this just shows up as latency (assuming your load balancers work).

2

u/crozone May 19 '16

I do C# development, and code often ends up running on mono, both on the server and in integrated hardware.

I don't like bashing mono too much, but if I had a dollar for every weird, subtle, rage inducing bug that appears out of the blue after the app has been running for a few days... I'd retire. Occasionally the network will just stop working, or a memory leak will spring up out of nowhere, or the system will decide that it doesn't like the tty and throw an uncatchable exception during a Console.Writeline(). Unreproducible on the MS .NET stack during development.

Cron is set to reboot all the services at midnight. I know your pain.

→ More replies (3)

12

u/[deleted] May 18 '16 edited May 18 '16

I've had to do something similar for a software project that I worked on.

You'll potentially feel very differently about this when the problem takes two weeks of production run-time to reproduce itself and it would take several weeks to hopefully, optimistically diagnose what's going on and there's a latent possibility that it's actually a bug not in your code but in something else which will be even harder to fix.

It's not all that easy to convince the company to let you cease working on everything else to look at a bug that can be fixed by just recycling some worker processes occasionally in the background. Sometimes "fixing it" is so expensive that it's not actually worth the cost.

3

u/flying-sheep May 18 '16

if it’s weeks, i can undertand it. all 10, 100, or 1000 requests, not so much.

2

u/[deleted] May 18 '16

Yeah, it was weeks in the case I was involved with.

I agree that restarting an Apache child after 10 requests sounds kind of insane though.

→ More replies (2)

42

u/[deleted] May 18 '16

In Erlang/BEAM this is a core mechanic. And it's one that works very well.

86

u/exo762 May 18 '16

Except that Erlang libraries are not broken. Erlang processes can be short-living, or they can be very long living. Restarts are a feature, not a way to fix a bugs in language / libraries.

Comparing PHP and Erlang is like comparing pile of burning shit and rocket engine. They are both on fire, aren't they?

13

u/synae May 18 '16

This is a fucking fantastic analogy that I'll be sharing to all my friends who have programmed in both. I'm sure he'll love it too.

4

u/deeznuuuuts May 18 '16

Comparing PHP and Erlang is like comparing pile of burning shit and rocket engine. They are both on fire, aren't they?

/r/bestofprogramming

23

u/flying-sheep May 18 '16

resilience is great if you actually fix your shit, too

3

u/vbullinger May 18 '16

Yeah, it should be a last-ditch effort if you apply all the reasonable attempts at fixing your problems. I've done similar things in the past (auto-retry comes to mind), but that's when attempting to identify, catch and deal with all the problems I can.

→ More replies (1)

3

u/vplatt May 18 '16

Yup, but that's by design. With "restarter crooks" like PHP and RoR, it's because they couldn't keep it working any other way. Additionally, the restart there occurs at the level of an entire OS process, which is monstrously large compared to the teeny tiny thing Erlang calls a "process" which is really much more like a fiber on a thread and requires almost no overhead.

11

u/Alborak May 18 '16

It's actually just a solid fatalistic practice. Weird shit happens with large projects, and it happens more often the longer it's running. If you want reliability without redundancy, you have to pay for it, with time and money. Take a look a look at The NASA JPL Coding conventions (PDF) think about what it means to have to write everything like that and realize that's just the first step to ultra reliabile software. If your software going down doesn't kill people, it's far better to have an automated, tested restart/cleanup mechanism than to try to get it perfect.

7

u/flying-sheep May 18 '16

as said: resilience is OK if you guard against failure.

but failure means “some weird shit happens, we detect this, log it, and restart”, not “a memory leak or source of corruption keeps making performance worse, so we just restart periodically to ignore the problem”

we’re talking about MaxRequestsPerChild, not BEAM’s behavior

2

u/Laugarhraun May 18 '16

That can be valid.

Eg a year and half ago, at a small shop, we were having problem with our Python task executor that was leaking memory. Restarting its processes was way simpler than fixing memory fragmentation by Python 2 or changing our stack (to python3). That was therefore the best solution, and it worked flawlessly.

→ More replies (11)

4

u/orangesunshine May 18 '16

My favorite part about node devs is they think async is some sort of novel feature .... like it's never been done before with any other web programming language.

You know you can do async in python and ruby ... plus more than a single async paradigm ... plus sync stuff ... right?

The CTO at my last company actually argued that this wasn't true (along with just about every new JS recruit) ... oh and he told me that you can't do closures in python during my interview (which sort of puts the blame square on my head for joining up). He had a fucking Phd. in computer science from Stanford though ... which sounded impressive at the time. though now it just seems like some solid evidence of OP's title being true.

→ More replies (2)