News for hackers. Stuff that matters.
Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by themgt on Thursday February 14, 2013 @01:00AM (#5217997)
I agree there should be a better way - it's just important to understand than Rails doesn't get any special treatment on a PaaS done correctly, so it's important to come up with a generic solution.

I think part of the solution would be customizable option(i.e.. how many requests can each dyno handle simultaneously), probably combined with intelligently monitoring/balancing proxy load so new requests always go to the least-loaded dyno.

Buildpacks could probably be used to parse of Gemfile/etc, see if you're using what mix of webrick/unicorn/rails/sinatra/rack-stream/goliath etc, and set an semi-intelligent default. But apps are increasingly unlike a checkout line. Apps are more like the supermarket, which is harder.

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by vidarh on Thursday February 14, 2013 @05:27AM (#5218815)
Rails doesn't need to be treated specially. All that is needed is a "maximum number of simultaneous connections to pass to this backend" setting coupled with load balancing by available slots rather than purely randomly.

The issue here isn't that Rails needs to be treated specially - this problem applies to various extent in any type of backend where some types of requests might turn out to be computationally heavy or require lots of IO. You can't magic away that: A request that takes 8 CPU seconds will take 8 CPU seconds. If you start piling more requests onto that server, response times will increase, even if some will keep responding, and if another 8 CPU second request hits too soon, chances increase that a third one will, and a fourth, and before you know it you might have a pileup where available resources for new requests on a specific instance are rapidly diminishing and response times shoot through the roof.

Pure random distribution is horrible for that reason pretty much regardless.

Now, doing "intelligent" routing is a lot easier for servers with some concurrency, as you can "just" have check requests and measure latency for the response and pick servers based on current low latency and get 90% there and that will be enough for most applications. Sure, the lower the concurrency, the more you risk having multiple heavy queries hit the same server and slow things down, and this request grows dramatically with the number of load balancers randomly receiving inbound requests to pass on, but at least you escape the total pileup more often.

But that's also a clue to one possible approach for non-concurrent servers: group them into buckets handled by a single active load balancer at a time and have front ends that identifies the right second layer load balancers. Shared state is now reduced to having the front end load balancers know which second layer load balancers are the currently active ones for each type of backend. It costs you an extra load balancer layer with according overhead. But don't you think OP would prefer an extra 10ms per request over the behaviour he's seen?

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by mononcqc on Thursday February 14, 2013 @08:01AM (#5219218)
I'm sure OP could prefer the extra 10ms, but then everyone else who can deal with random dispatching right now has to pay a 10ms penalty because OP built his stuff on a technology that can deal with only one request at a time on a server, which boggles the mind to begin with.
Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by vidarh on Thursday February 14, 2013 @11:11AM (#5220066)
Why? The system could easily be built so that it by default only aggregates those services where the configuration indicates they can handle a concurrency below a certain level, and does random balancing of everything else.

The "everyone else who can deal with random dispatching right now" is a much smaller group than you think. Anyone who has long running requests that grind the CPU or disk when running, will be at high risk of seeing horribly nasty effects from random dispatching, no matter whether their stack in ideal conditions have no problem handling concurrent requests.

It's just less immediately apparent, as any dynos that start aggregating multiple long running requests will "just" get slower and slower instead of blocking normally low-latency requests totally.

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by DigitalJack on Thursday February 14, 2013 @11:37AM (#5220221)
"The system could easily be built so that it by default only aggregates those services where the configuration indicates they can handle a concurrency below a certain level, and does random balancing of everything else."

Let me know when you are done with that.

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by vidarh on Thursday February 14, 2013 @12:02PM (#5220375)
I've built fairly large haproxy based infrastructures, thank you very much. Doing this is not particularly challenging.

Actually what I'd probably do for a setup like this would be to balance by the Host: header, and simply have the second layer be a suitable set of haproxy instances balancing each by least connections.

Immediately vastly better than random.

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by themgt on Thursday February 14, 2013 @03:57PM (#5222209)
Haproxy doesn't support dynamic configurations as far as I know, which is a serious problem if you're letting lots of people add/change domains and scale backends up/down dynamically. A Heroku haproxy would probably need to be restarted multiple times a second due to config changes. Nginx can do dynamic backends with lua & redis, but it can't use the built-in upstream backend balancing/failover logic if you do.
Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by vidarh on Thursday February 14, 2013 @09:31PM (#5224075)
While it doesn't support dynamic configurations, it does support hot reconfiguration (the new daemon signals the old processes to gracefully finish up and shut down), and reconfigures very rapidly. You still don't want to restart it multiple times a second, but you don't need to:

A two layer approach largely prevents this from being a problem. You can afford total overkill in terms of the number of haproxies as they're so lightweight - running a few hundred individual haproxy instances with separate configs even on a single box is no big deal.

The primaries would rarely need to change configs. You can route sets customers to specific sets of second layer backends with ACL's on short substrings of the hostname (e.g. two letter combinations), so that you know which set of backends each hostname you handle maps to, and then further balance on the full host header within that set to enable the second layer to balance on least-connections to get the desired effect.

That lets you "just" rewrite the configs and hot-reconfigure the subset of second layer proxies handling customers that falls in the same set on modifications. If your customer set is large enough, you "just" break out the frontend into a larger number of backends.

Frankly, part of the beauty of haproxy is that it is so light that you could probably afford a third layer - a static primary layer grouping customers into buckets, a dynamic second layer routing individual hostnames (requiring reconfiguration when adding/removing customers in that bucket) to a third layer of individual customer-specific haproxies.

So while you would restart some haproxy multiple times a second, the restarts could trivially be spread out over a large pool of individual instances.

Alternatively, "throwing together" a second or third layer using iptables either directly or via keepalived - which does let you do dynamic reconfiguration trivially, and also supportes least-connections load balancing - is also fairly easy.

But my point was not to advocate this as the best solution for somewhere like Heroku - it doesn't take a very large setup before a custom solution starts to pay off.

My point was merely that even with an off the shelf solution like haproxy, throwing together a workable solution that beats random balancing is not all that hard - there's a large number of viable solutions -, so there really is no excuse not to for someone building a PaaS.

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by badgar on Thursday February 14, 2013 @04:48PM (#5222619)
You're right. They'd have to instead build a load-balancer that solves the problem, and that's too darn hard.
Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by dragonwriter on Thursday February 14, 2013 @10:45AM (#5219935)
> it's just important to understand than Rails doesn't get any special treatment on a PaaS done correctly, so it's important to come up with a generic solution.

Its kind of weird to describe not optimizing the entire platform provided to apps as "PaaS done correctly". Making a PaaS more generic has a certain kind of value in terms of broadening the audience and enabling heterogenous systems to be implemented on it, but if you are doing that by sacrificing the optimization of the individual application platforms available, you are losing some of what makes a PaaS valuable as opposed to roll-your-own platform support on top of a generic IaaS.

Its especially problematic to say that worsening support for the main existing app framework in use on an establish PaaS and giving existing customers orders of magnitude less value for their money is doing something right.

> I think part of the solution would be customizable option

That's probably a good idea, though the default for existing apps should not have changed, especially without clear up-front notice.

> But apps are increasingly unlike a checkout line.

Existing apps are, for the most part, exactly as much like a checkout line as they were before the unannounced change.

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by skrebbel on Thursday February 14, 2013 @01:43AM (#5218111)
> it's just important to understand than Rails doesn't get any special treatment on a PaaS done correctly

Why is it only "done correctly" if it does not account for specific properties of the technology used by a particular customer?

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by themgt on Thursday February 14, 2013 @02:08AM (#5218191)
Because PaaS is a generic technology for running and scaling applications with a multitude of different language/framework/stacks, and many/most of those apps do not share the specific properties of single-threaded Rails (including many Ruby/Rails apps!)

And Rails 4 is going to bake-in "live streaming", making single-threaded app servers even more of an edge case.

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by bradleyjg on Thursday February 14, 2013 @09:39AM (#5219596)
That sounds a lot more like IaaS to me. PaaS should be providing the entire platform, hence the name.

The entire promise of the space is that the customer only has to worry about his own code and perhaps tweaking a few knobs.

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by skrebbel on Thursday February 14, 2013 @02:16AM (#5218211)
That's like saying Craigslist did it correctly and AirBnB didn't because AirBnB is only tailoring to a specific segment of the world's supply and demand market.

Rails is very widely used. How can you consider that an edge case?

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by themgt on Thursday February 14, 2013 @03:12AM (#5218383)
It's like saying EC2 should tailor its virtualization to Fedora 16, or Mac OS X should tailor its windowing system to Photoshop CS4, or Apache should tailor mod_proxy to Joomla. There may be specific attributes of popular applications that need to be adapted to, but those adaptations need to be built in a generic way and exposed through a standard API.

Since even many Rails apps now do not follow a single threaded request-response model, that model of running a web application needs to be considered as one case of many, and building a platform that supports many/all use-cases as well as possible is more complicated than building a platform that fits one use case like a leather glove.

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by doktrin on Thursday February 14, 2013 @03:54AM (#5218523)
> Mac OS X should tailor its windowing system to Photoshop CS4

I think statements like these obscure away the very tight coupling Heroku has historically had with Rails. While certainly Heroku now perhaps envisions itself as a do-it-all PaaS, there's no denying Rails at one point (and, numerically, perhaps still) was their bread and butter.

While I don't have numbers to support or refute the assertion that "most Rails apps are primarily single threaded", my suspicion is that this is in fact still the case.

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by skrebbel on Thursday February 14, 2013 @05:36AM (#5218839)
> or Mac OS X should tailor its windowing system to Photoshop CS4

I'm taking this example out specifically, because it illustrates my point quite nicely.

If there were a sizeable community of people who only wanted to use a computer for Photoshop, and tailoring the windowing system to them made it a significant usability improvement for those people, then it would be a completely imaginable situation that upon first opening your brand new Mac, it'd ask you whether you're one of those Photoshop people and want the special windowing system setup.

Well, ok, haha Apple and customizing anything for anyone, ever. But many other vendors might make such a choice.

The apparent stubborn refusal of many PaaS services, including Heroku and yours, to particularly tailor to a very common configuration of Rails sounds like a hole in the market, to me. As a customer, I don't care whether this is "incorrect" because Rails does not conform to some yet-to-be-defined standard or simply because the PaaS doesn't have their shit together. The customer experience is the same: I'm running a blog tutorial app, and the performance sucks.

Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by regularfry on Thursday February 14, 2013 @06:26AM (#5218963)
Microsoft have definitely done exactly this. Windows versions have famously been "rebroken" in development to keep bug-for-bug compatibility so they didn't break big third party applications.
Re:Heroku's Ugly Secret: The story of how the cloud-king tur... by papsosouid on Thursday February 14, 2013 @11:34AM (#5220210)
The 'P' stands for platform. Providing the platform as a service absolutely means catering to the specific needs of the platform. There is no generic platform. If you want to support multiple platforms, then you support multiple platforms. You don't stop supporting any platform at all.