cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

rpc: 99th percentile round-trip latency numbers seem too high

Open a-robinson opened this issue 9 years ago • 31 comments

We recently added a metric tracking the round-trip latency of the heartbeat pings we send on all our inter-node connections (#13533). While the 50th percentile measurements look reasonable (a few milliseconds), the 99th percentile readings on all of our prod clusters are pretty concerning.

Our clusters on Azure have a 99th percentile of around 50-100ms:

screen shot 2017-02-22 at 4 23 36 pm

And our cluster on GCE has a 99th percentile around 20-40ms:

screen shot 2017-02-22 at 4 29 23 pm

We should figure out what the cause of this is, since those are very bad numbers for requests that don't require doing any work or traversing any datacenter boundaries.

Jira issue: CRDB-69689

Jira issue: CRDB-69690

a-robinson avatar Feb 22 '17 21:02 a-robinson

It's not likely to be a virtualization/environmental issue - I just ran 700 iterations of ping and never saw any latency higher than 5.8ms.

a-robinson avatar Feb 22 '17 21:02 a-robinson

Just to play devil's advocate real quick - we are not measuring these using a monotonic clock, are we?

tamird avatar Feb 22 '17 21:02 tamird

Indeed we're not, just a standard clock. It's a good point that we should switch, although I can't imagine that would account for such a consistently high measurement. I'd think that would only cause spikes.

a-robinson avatar Feb 22 '17 21:02 a-robinson

GRPC heartbeats are more than a simple network round trip. Everything is multiplexed onto a single HTTP/2 connection, so there's locking and queuing at that layer. If a snapshot is being sent the heartbeat may have to wait for that data to be written (looks like grpc writes in 16KiB frames), and for flow control at both the TCP and HTTP/2 levels.

bdarnell avatar Feb 22 '17 22:02 bdarnell

Thanks for the insight, @bdarnell. Do you think it's worth investigating further? I was going to add a bit of tracing to the heartbeat code so we could get more detail than a single span for the entire heartbeat in lightstep, but that won't give us much more detail other than a very vague idea of where the request is getting delayed.

a-robinson avatar Feb 22 '17 22:02 a-robinson

Good point about everything being multiplexed on a single HTTP/2 connection, though I doubt we're sending so many snapshots on all these clusters.

Probably should kill the load on one of the clusters and check to see if the latencies drop to more reasonable values.

Also, 5ms ping times seem high for within a datacenter.

petermattis avatar Feb 22 '17 22:02 petermattis

The average was in the 1.5-2ms range, with just a couple outliers. I think that's about all you can expect when running on cloud VMs - you're going to have worse tail performance.

a-robinson avatar Feb 22 '17 22:02 a-robinson

Things certainly get better with traffic disabled, although still a little on the high end:

screen shot 2017-02-22 at 6 07 07 pm

In case it's a little tough to tell, they've dropped down to about 15-30ms at p99. Absolutely all variability left the p50 measurement once the load generators were disabled, settling down to right around what my pings were showing (~1.8ms):

screen shot 2017-02-22 at 6 09 28 pm

a-robinson avatar Feb 22 '17 23:02 a-robinson

And since @mberhault kindly pointed out that I hadn't removed all the work, the 99th percentile latency has indeed dropped all the way down to the 3-6ms range that I was seeing in ping:

screen shot 2017-02-22 at 6 24 29 pm

Thus, it is indeed the connection getting legitimately clogged up. This may be something that needs fixing, but it is a factor of the load on the system.

a-robinson avatar Feb 22 '17 23:02 a-robinson

Those latencies still see high to me. Checking on cobalt just now, I'm seeing avg ping times of ~600us when using the internal IP addresses and 1.8ms when using the DNS names. Omega (GCE) is showing avg ping times of ~300us. Those numbers are more in line with my expectations.

petermattis avatar Feb 23 '17 03:02 petermattis

Ah, brilliant, Azure's external IP routing is super slow. I had just assumed it was terribly slow regardless. I'm seeing the same numbers. We may want to modify our supervisor configs to bind to / advertise external IPs rather than hostnames since that's a pretty major difference.

I'm also a bit surprised just how costly GCE's external IP virtualization is -- I see around 280us for external vs 140us for internal. I thought it was better than that.

a-robinson avatar Feb 23 '17 04:02 a-robinson

We may want to modify our supervisor configs to bind to / advertise external IPs rather than hostnames since that's a pretty major difference.

Bind to internal IPs, right?

Cc @mberhault

petermattis avatar Feb 23 '17 13:02 petermattis

DNS names don't matter, it's the IP addresses they map to. We recently moved a few supervisor configs to use the external DNS names. We should stop doing that. The internal dns names (eg: cockroach-violet-0001) will be just fine. indigo is the only exception since the nodes are not in the same virtual private network.

There seems to be a massive discrepancy between cluster (different zones, slightly different machine type): violet: centralus, D3v2: 350us internal / 590us external

cockroach@cockroach-violet-0001:~$ ping -i 0.2 -q -c 50 cockroach-violet-0002
PING cockroach-violet-0002.trlnlrou2h1etawy34fljx303d.gx.internal.cloudapp.net (192.168.1.5) 56(84) bytes of data.
50 packets transmitted, 50 received, 0% packet loss, time 9809ms
rtt min/avg/max/mdev = 0.206/0.353/0.872/0.119 ms

cockroach@cockroach-violet-0001:~$ ping -i 0.2 -q -c 50 cockroach-violet-0002.crdb.io
PING cockroach-violet-0002.crdb.io (40.69.150.212) 56(84) bytes of data.
50 packets transmitted, 50 received, 0% packet loss, time 9804ms
rtt min/avg/max/mdev = 0.387/0.589/1.986/0.219 ms

cobalt: eastus, D3: 700us internal / 1400us external

cockroach@cockroach-cobalt-01:~$ ping -i 0.2 -q -c 50 cockroach-cobalt-02
PING cockroach-cobalt-02.hpuurpc1pare3bbkgbzmmhanoe.bx.internal.cloudapp.net (192.168.1.5) 56(84) bytes of data.
50 packets transmitted, 50 received, 0% packet loss, time 9810ms
rtt min/avg/max/mdev = 0.405/0.702/2.431/0.345 ms

cockroach@cockroach-cobalt-01:~$ ping -i 0.2 -q -c 50 cockroach-cobalt-0002.crdb.io
PING cockroach-cobalt-0002.crdb.io (40.117.102.161) 56(84) bytes of data.
50 packets transmitted, 50 received, 0% packet loss, time 9833ms
rtt min/avg/max/mdev = 1.154/1.410/3.498/0.326 ms

omega: 190us internal / 420us external

cockroach@cockroach-omega-0001:~$ ping -i 0.2 -q -c 50 cockroach-omega-0002
PING cockroach-omega-0002.c.cockroach-shared.internal (10.142.0.4) 56(84) bytes of data.
ics ---
50 packets transmitted, 50 received, 0% packet loss, time 9805ms
rtt min/avg/max/mdev = 0.116/0.192/0.840/0.153 ms

cockroach@cockroach-omega-0001:~$ ping -i 0.2 -q -c 50 cockroach-omega-0002.crdb.io
PING cockroach-omega-0002.crdb.io (104.196.180.58) 56(84) bytes of data.
50 packets transmitted, 50 received, 0% packet loss, time 9804ms
rtt min/avg/max/mdev = 0.227/0.417/2.835/0.397 ms

The difference between omega and violet could be explained by the fact that the host OS on Azure is still Windows, and it's historically had a crappy networking stack. No idea what could cause the cobalt numbers though, I'll run basic pings on everything I can find, then try to dig further.

mberhault avatar Feb 23 '17 13:02 mberhault

Except ultimately, the --join flag doesn't matter, it's the --advertize-host that does, and the only place we're specifying it is indigo. All others just end up using their local hostname, which resolves to the internal IP for nodes on the same network.

So the only cluster using external IPs for internal communication is indigo, and I don't think there's much we can do about that, unless we introduce a mechanism allowing a different advertize-host for nodes in the same network vs those outside it.

mberhault avatar Feb 23 '17 13:02 mberhault

Yeah, sorry, I can't type. I meant that we should use "internal rather than external", not "external rather than hostname".

Although I was also not paying close enough attention and thought that cobalt advertising itself as cockroach-cobalt-01 was bad, even though that's just the internally-scoped hostname, not the external hostname, so it is fine.

That means the 1.8ms 50th percentile and 3-6ms 99th percentile for the heartbeat RPCs are still pretty bad.

a-robinson avatar Feb 23 '17 14:02 a-robinson

Seems like there is still something funky here. Hard to believe that gRPC round-trip time on an idle cluster is 150% slower than ping time. And given the timings, I'm suspicious that somehow we're using the external IPs even though it appears we aren't.

petermattis avatar Feb 23 '17 14:02 petermattis

I wrote a simple gRPC service which shows 1-1.5ms RTTs on cobalt, while ping is showing 600ms RTTs. Next step would be to try something even simpler that just uses sockets.

petermattis avatar Feb 24 '17 16:02 petermattis

This is still pretty abysmal, even after a build including #14939 was pushed. Our end user tail latency is bound to be terrible if our heartbeat tail latency is terrible. Picking this back up again.

a-robinson avatar Apr 17 '17 20:04 a-robinson

After some investigation today, I think we might have to table this until after 1.0.

I first tried putting the heartbeat pings onto their own connections, separated from all our other grpc traffic, but that had a negligible effect on latency at the 50th, 95th, and 99th percentiles.

With the heartbeats still on their own connections, I then added basic tracing so that we could tell how much of the request time gets spent getting the request from the client to the server and how much gets spent getting it from the server back to the client. There was no consistent pattern, meaning that there probably isn't a single bottleneck delaying the requests.

It also doesn't look like grpc is blocking on sends, judging by some simple timing logic added into the client path. It looked like data was flushed out to the net.Conn synchronously within the sending logic I instrumented, but it's possible I made a mistake when spelunking the code.

For the sake of reproduction and making sure I'm not doing things totally wrong, I was running on cobalt with the cockroachdb diff in https://github.com/a-robinson/cockroach/commit/0b14f7cb2c1b65a012a9772a4691cee7a567be3a and the grpc logging diff in https://gist.github.com/a-robinson/0673ed8f7cf5c5e4feea69ceb195c41c, and some example lightstep traces from the instrumented heartbeat pings are below. servePing is when the request reached our server code for the Ping rpc method.

screen shot 2017-04-18 at 4 51 34 pm screen shot 2017-04-18 at 4 51 38 pm screen shot 2017-04-18 at 4 51 44 pm screen shot 2017-04-18 at 4 51 49 pm screen shot 2017-04-18 at 4 51 53 pm

a-robinson avatar Apr 18 '17 21:04 a-robinson

So I'm going to move this out of 1.0 since I think too much time and too big of a change may be needed to improve things, but I'll take another look at it if we magically finish up all our other 1.0 work early.

a-robinson avatar Apr 18 '17 21:04 a-robinson