iconara/ione-rpc — pull request #4 by karinsofia (2014-12-10 23:37:38+00:00)
Title: Cancel timeout timer when request has been completed

In the current implementation is each request with a timeout scheduling a timer. This timer will be triggered after a given amount of time to check if the request has been completed or not. If it has not been completed it fails the request with a TimeoutError.

This PR suggest that when a request is handled, the timeout’s timer of the request is canceled. Cancelling its timer prevents the scheduler to spend time dealing with it. It also removes the call, performed for each request, to see if the request has been completed when its timer times out. In case a timeout actually occur, the timeout’s future #on_value will be triggered and simply fail the request.

##### Benchmark

A benchmark performed using a simple client - server setup, sending 20.000 requests.

timeout | master (ruby-2.1.1) | cancel-timeouts (ruby-2.1.1) | master (jruby-1.7.16.1) | cancel-timeouts (jruby-1.7.16.1)
-------- | ------------- | ------------- | -----| ------|
30 | 4.560000 1.890000 6.450000 ( 5.872910) | 184.950000 5.210000 190.160000 (189.704804) | 14.550000 3.770000 18.320000 ( 10.778000) | 14.620000 3.930000 18.550000 ( 10.903000)
10 | 4.220000 1.780000 6.000000 ( 5.414380) | 111.920000 3.800000 115.720000 (115.084632) | 14.700000 3.800000 18.500000 ( 10.920000) | 14.490000 3.840000 18.330000 ( 10.682000)
1 | 1.770000 5.920000 ( 5.364615) | 35.560000 2.800000 38.360000 ( 37.739382) | 13.610000 3.580000 17.190000 ( 10.258000) | 14.940000 3.740000 18.680000 ( 10.985000)

As one can see from the result above was there was latency improvement when cancelling timeouts using Ruby, while JRuby appears unaffected by the change (doing some JVM magic).