hiredis-rb icon indicating copy to clipboard operation
hiredis-rb copied to clipboard

Implement C-level ping?

Open mperham opened this issue 4 years ago • 3 comments

Hi, I've been trying to monitor Redis network latency within Sidekiq by using PING but I've learned that a process pegged at 100% CPU will dramatically overstate latency due to thread scheduling latency around the GVL. If you have 10 jobs crunching numbers, it may take 50-100ms to get a Ruby thread scheduled to process the PONG. Would you be interested in a special PING impl which is designed only to calculate round trip time in C, so as to avoid Ruby VM overhead?

I'm thinking something as simple as:

> redis.rtt_us
=> 267

where the result is the calculated RTT in µs.

See also https://github.com/mperham/sidekiq/issues/5025

mperham avatar Oct 14 '21 22:10 mperham

it may take 50-100ms to get a Ruby thread scheduled to process the PONG

More than that, even. Threads are only interrupted every 100ms, so the worse case scenario is NUMBER_OF_THREADS * 100ms. Ouch!

nateberkopec avatar Oct 14 '21 23:10 nateberkopec

@byroot is this something you would be interested in providing in hiredis-client?

mperham avatar Apr 26 '23 18:04 mperham

Hum, perhaps, I'd need to have a look at how doable it would be. As I'd need to skip the reader code because it needs the GVL.

I'll have a quick look tomorrow.

byroot avatar Apr 26 '23 18:04 byroot