Shortly before stable 1.0 was released, a patch was applied to trunk to avoid connection timeout errors. Unfortunately, the implementation had severe performance implications. This patch resurrects performance charteristics comparable to the point before the patch went in.
Instead of clearing the connection cache after each request, we leave it as is. We add a @last_verification variable to the connection and a @@connection_cache_timeout variable to class ActiveRecord::Base. Before a request is processed, verify_connection_cache! gets called on AR::Base. connection.active? is called only when @@connection_cache_timeout seconds have passed since the last verification. This greatly reduces the number of DB calls.
Secondly, our patch reduces the number of entries in the connection cache to the number of defined connections (instead of having one cache entry for each AR class used during a certain number of requests).
Performance impact:
perf data file 1: 02-27.all.trunk
requests=1000, options=-bm=all -mysql_session -fast_routes -fast_readers -lib=trunk
perf data file 2: 02-27.all.trunk2
requests=1000, options=-bm=all -mysql_session -fast_routes -fast_readers -lib=trunk2
page c1 real c2 real c1 r/s c2 r/s c1 ms/r c2 ms/r c1/c2
1: 1.42228 1.33638 703.1 748.3 1.42 1.34 1.06
2: 1.67259 1.58068 597.9 632.6 1.67 1.58 1.06
3: 1.75018 1.65918 571.4 602.7 1.75 1.66 1.05
4: 1.73553 1.64860 576.2 606.6 1.74 1.65 1.05
5: 4.15005 3.89853 241.0 256.5 4.15 3.90 1.06
6: 5.03691 4.83803 198.5 206.7 5.04 4.84 1.04
7: 5.14496 4.94910 194.4 202.1 5.14 4.95 1.04
8: 4.99811 4.86160 200.1 205.7 5.00 4.86 1.03
urls:
1: /empty/index
2: /welcome/index
3: /rezept/index
4: /rezept/myknzlpzl
5: /rezept/show/713
6: /rezept/cat/Hauptspeise
7: /rezept/cat/Hauptspeise?page=5
8: /rezept/letter/G