redis / hiredis-rb

Ruby wrapper for hiredis
BSD 3-Clause "New" or "Revised" License
319 stars 90 forks source link

Implement C-level ping? #74

Open mperham opened 2 years ago

mperham commented 2 years ago

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

nateberkopec commented 2 years ago

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!

mperham commented 1 year ago

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

byroot commented 1 year ago

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.