rpc: 99th percentile round-trip latency numbers seem too high
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:
And our cluster on GCE has a 99th percentile around 20-40ms:
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
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.
Just to play devil's advocate real quick - we are not measuring these using a monotonic clock, are we?
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.
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.
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.
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.
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.
Things certainly get better with traffic disabled, although still a little on the high end:
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):

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:
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.