Decoding gRPC Latency
Understanding your gRPC latency the right way.
First thing first, before testing gRPC latency, make sure you follow the rule of thumb.
Your server should be in the same region as the gRPC you are streaming from.
In simple words, if you are connecting to grpc.ams.shyft.to, your server should also be in Amsterdam. Same applies for all other regions. Now that we are connecting from the same region, lets answer the elephant in the room.
"Why am I getting 1s or more latency latency with gRPC. Isn't that slow?"
TLDR;
Subtract 500ms from your latency since Solana doesnβt store milliseconds, which leads to a loss of precision. For instance, a transaction occurring at 07:46:46:900 would have a block time of 07:46:46:000. It's better to use the middle of the second for calculations.
The most obvious formula for gRPC latency is
transaction receive time - transaction block time = gRPC latency
What we are missing here is the fact that Solana doesn't store milliseconds in its ledger, leading to loss of precision and inaccurate calculations. To understand this more, lets look at some actual data. Below are some blocks with their block times.
319464973: 07:46:46
319464974: 07:46:46
319464975: 07:46:47
319464976: 07:46:47
As you can see, there's no milliseconds on Solana, all transactions in these blocks will also have exactly the same time 07:46:46:000 and 07:46:47:000. We know Solana generate 2-3 blocks per second, so in reality these blocks would be distributed across the second between 000 to 999ms. So now imagine if a transaction really happens at 07:46:46:900, on Solana its block time would become 07:46:47:000. If you receive it at 07:46:47:200 gRPC latency would come as
07:46:47:200 - 07:46:46:000 = 1.2 seconds
While in reality its around 300ms. So a more intuitive way to approximate gRPC latency is to pick the middle of the second, which makes our formula as
gRPC latency = transaction receive time - (transaction block time + 500ms)
This is not highly accurate but gives a better approximation of the latency that we are receiving.
Last updated
Was this helpful?