reinh / statsd

A Ruby Statsd client that isn't a direct port of the Python example code. Because Ruby isn't Python.
MIT License
411 stars 154 forks source link

Add the ability to pre-connect to the UDPSocket with `connect` #50

Closed quirkey closed 8 years ago

quirkey commented 10 years ago

In testing with a previous version of the statsd-ruby gem we noticed that a lot of time was spent sending these UDP messages. Looking at the Ruby API, I noticed that by calling connect on the socket ahead of time, future sends on the socket were significantly faster.

This adds a connect method, that when called, no longer needs to send host/port with every send.

In testing in production, it has reduced calls by greater than two orders of magnitude

       user     system      total        real
udp with connect  0.010000   0.000000   0.010000 (  0.074522)
udp without connect  0.120000   0.530000   0.650000 ( 13.096515)
statsd with connect  0.000000   0.090000   0.090000 (  0.103520)
statsd without connect  0.100000   0.620000   0.720000 ( 13.483539)
cheald commented 10 years ago

I tried this at one point, but it was rejected for a few (valid) reasons. See the discusson on #30.

quirkey commented 10 years ago

@cheald Ah! thanks for the heads up, great info. I still think this patch is useful/valid even though it puts some restrictions on the connection itself. Either way, its optional and lets the user choose if they want to skip the re-connect.