Live data from Hacker News

On Sharding

tbray.org

11–20 of 44 posts

Re: On Sharding

#11
post #7

> Load-sensitivity is one “smart” approach. The idea is that you keep track of the load on each shard, and selectively route traffic to the lightly-loaded ones and away from the busy ones. Simplest thing is, if you have some sort of load metric, always pick the shard with the lowest value. Gotta be super careful with this one. We did this at reddit and it bit us bad. The problem was as soon as the load on a machine w…

Adding hysteresis definitely helps to stabilize issues like this. Using rolling windows or exponentially decayed weighting has worked out well in my experience. In general, it seems like load based routing can be quite perfidious if you get the heuristic for “load” wrong.

I worked on a system that used total connections as our heuristic, measured by the load balancer. The problem we experienced was that some failure scenarios could cause requests to fail quickly compared to normal traffic. In effect what would happen is that a host would go into a bad state, start failing requests with a lower latency than normal traffic causing the load balancer to route an increasing amount of traffic to the bad host. This happened because the load balancer was only capable of measuring connections and didn’t discriminate between good/bad responses.

We ended up injecting fake latency into bad responses at the application layer which worked to prevent this sort of “black hole” effect.

Re: On Sharding

#12
post #6

Another good strategy for load balancing/sharding that always strikes me as simple but also devilishly cleaver is random pick two: https://brooker.co.za/blog/2012/01/17/two-random.html

It looks at mean queue time, not worst case time.

Re: On Sharding

#13
Sorta related:

I managed a team that built a 5x 1000 node distributed setup 10+ years ago.

We ended up going with

a) short DNS TTL + a custom DNS server that sent people to the closest cluster (with some intra-communication to avoid sending people to broken clusters)

b) in each cluster; three layers: 1) Linux keepalived load balancing, 2) Our custom HTTP/TLS-level loadbalancers (~20 nodes per DC), 3) our application (~1000 nodes per DC)

A typical node had 24 (4x6) CPU cores when we started and 48 (4x12) towards the end.

These were not GC/AWS nodes, we were buying hardware directly from IBM/HP/Dell/AMD/Intel/SuperMicro and flying our own people out to mount them in DCs that we hired. Intel gave us some insane rebates when they were're recovering from the AMD dominance.

Load-balancing policy: we just randomized targets, but kept sticky sessions. Nodes were stateless, except for shared app properties - we built a separate globally/dc-aware distributed key-value store - that was a whole new thing 12 years ago we built based on the vague concept of AWS Dynamo. App nodes reported for duty to the load balancers when they were healthy.

We had a static country-to-preferred-DC mapping. That worked fine at this scale.

This setup worked fine for a decade and 250M+ MAUs. We had excellent availability.

At some point like 10 years ago a kinda well known US-based board member really, really wanted to us to move to AWS. So we did the cost calculations and realized it would cost like 8X more to host the service on AWS. That shut him up.

Different times. It's so much easier now with AWS/GC to build large-scale services. But also so much more expensive - still! I wonder how long that can last until the concept of dealing with computation, network and storage really becomes a commodity.

Re: On Sharding

#14
post #12
post #6

Another good strategy for load balancing/sharding that always strikes me as simple but also devilishly cleaver is random pick two: https://brooker.co.za/blog/2012/01/17/two-random.html

It looks at mean queue time, not worst case time.

The article linked does, yes. The paper the article is based on (linked in the article) has a proof for worst case load if you’re interested in the details.

Edit: Link to paper http://www.eecs.harvard.edu/~michaelm/postscripts/handbook20...

Re: On Sharding

#15
post #7

> Load-sensitivity is one “smart” approach. The idea is that you keep track of the load on each shard, and selectively route traffic to the lightly-loaded ones and away from the busy ones. Simplest thing is, if you have some sort of load metric, always pick the shard with the lowest value. Gotta be super careful with this one. We did this at reddit and it bit us bad. The problem was as soon as the load on a machine w…

Per Brendan Gregg's Gesamptkunstwerk, BPF Performance Tools, I feel like you should be able to measure instructions per cycle at the service level. Even in the cloud if exposed by Xen. And even at the resource utilization level for each container.

http://www.brendangregg.com/bpf-performance-tools-book.html

Of course, you can always just use cloudflare ;)

Re: On Sharding

#16
post #10

My favorite sharding/load balancing algorithm is Highest Random Weight, or Rendezvous hashing [0]. It has all the benefits of consistent key hashing without the hotspots, and it doesn't require any coordination between nodes. [0] https://en.wikipedia.org/wiki/Rendezvous_hashing

Squid (http cache) uses Rendezvous Hashing, iirc. Google's Maglev Hash and Jump Hash are other alternatives that spring to mind: https://medium.com/@dgryski/consistent-hashing-algorithmic-t...

Two years or so back, I stumbled on power-of-2 load balancing via Twitter Finagle documentation. Found it pretty interesting. Here is a relevant news.yc discussion: https://news.ycombinator.com/item?id=14640811

And of course, the exponential weighted moving average is a good algorithm too. It is, I believe, used by Elasticsearch. Cloudflare blogged abt using it, as well: https://blog.cloudflare.com/i-wanna-go-fast-load-balancing-d...

Re: On Sharding

#17
post #5
post #4

Def worth clicking through to the shuffle sharding thread. Simple concept (and somewhat common in my experience) but I’ve never seen the analysis before.

Took me a long time to find (couldn't contrast the link), here it is: https://twitter.com/colmmacc/status/1034492056968736768

Some more resources re Shuffle Sharing: https://news.ycombinator.com/item?id=19291163

Also see, this nice little blog post: https://maisonbisson.com/post/hash-rings-sharding-request-re...

Re: On Sharding

#19
post #7

> Load-sensitivity is one “smart” approach. The idea is that you keep track of the load on each shard, and selectively route traffic to the lightly-loaded ones and away from the busy ones. Simplest thing is, if you have some sort of load metric, always pick the shard with the lowest value. Gotta be super careful with this one. We did this at reddit and it bit us bad. The problem was as soon as the load on a machine w…

This sounds a lot like the control-theory problem of balancing the proportional, integral, and derivative coefficients of a PID controller [1]?

I'm curious how you reached this condition as a requirement:

> The moral of the story here is make sure you pick a metric that reacts to the change in request rate as quickly as your request rate changes!

It makes sense intuitively, but I'm having trouble proving to myself that this is necessary+sufficient.

[1]: https://en.wikipedia.org/wiki/PID_controller

Re: On Sharding

#20
post #5
post #4

Def worth clicking through to the shuffle sharding thread. Simple concept (and somewhat common in my experience) but I’ve never seen the analysis before.

Took me a long time to find (couldn't contrast the link), here it is: https://twitter.com/colmmacc/status/1034492056968736768

Here's a threadreaderapp version https://threadreaderapp.com/thread/1034492056968736768.html
Post reply on HN