rethinkdb / rethinkdb-go

Go language driver for RethinkDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Connection pool performance

CMogilko opened this issue · comments

Some documentary ticket.
Some time ago rethinkdb can't do parallel queries in a single connection. Then query token was introduced but go driver was using it wrong until v6.
v5 has old connection pool over fatih/pool.v2, but that pool is suitable only for one connection - one query pattern. If there are more queries than pool capacity, then a new connection is created and destroyed after query is done.
If you service is doing many queries at time, you can easy run out of sockets. (a simple benchmark on v5 does this)
v6 has a rethinked new connection pool with connection reusage. No more extra Dials while quering.

v6

BenchmarkConnectionPoolLightweightQuery_Single
BenchmarkConnectionPoolLightweightQuery_Single                       595           2048488 ns/op            4516 B/op         45 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-2                     560           1828305 ns/op            4516 B/op         45 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-4                     709           1996768 ns/op            4518 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-8                     562           2062675 ns/op            4522 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-16                    609           3761521 ns/op            4524 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-24                    492           2479450 ns/op            4523 B/op         45 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-32                    546           2399584 ns/op            4532 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-64                    475           2801836 ns/op            4533 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-128                   548           2500576 ns/op            4546 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-256                   508           2429339 ns/op            4582 B/op         45 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel
BenchmarkConnectionPoolLightweightQuery_Parallel                     552           2728374 ns/op            4517 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-2                  1010           1258768 ns/op            4518 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-4                  1947            699586 ns/op            4521 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-8                  2203            480078 ns/op            4526 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-16                 4977            266119 ns/op            4528 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-24                 7076            165385 ns/op            4531 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-32                 8766            159120 ns/op            4533 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-64                10000            107530 ns/op            4542 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-128               16926             62342 ns/op            4554 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-256               20614             61893 ns/op            4578 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel3X
BenchmarkConnectionPoolLightweightQuery_Parallel3X                  1627            853209 ns/op            4518 B/op         45 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel3X-2                2071            543407 ns/op            4522 B/op         45 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel3X-4                4532            321287 ns/op            4524 B/op         45 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel3X-8                7311            176786 ns/op            4526 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel3X-16              11239            111640 ns/op            4528 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel3X-24              16975            114961 ns/op            4530 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel3X-32              17253             78070 ns/op            4533 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel3X-64              14997             69311 ns/op            4539 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel3X-128             16722             77537 ns/op            4550 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel3X-256             15121             71858 ns/op            4573 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel10X
BenchmarkConnectionPoolLightweightQuery_Parallel10X                 2649            579236 ns/op            4522 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel10X-2               3511            339974 ns/op            4524 B/op         45 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel10X-4               6448            162320 ns/op            4525 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel10X-8              10000            124900 ns/op            4526 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel10X-16             17800             67956 ns/op            4528 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel10X-24             20730             93995 ns/op            4530 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel10X-32             17652            103584 ns/op            4532 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel10X-64              2980            490010 ns/op            4558 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel10X-128             7974            144925 ns/op            4573 B/op         46 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel10X-256            15853             92084 ns/op            4568 B/op         46 allocs/op

v5

BenchmarkConnectionPoolLightweightQuery_Single
BenchmarkConnectionPoolLightweightQuery_Single              	     313	   3628790 ns/op	    4613 B/op	      47 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-2            	     378	   4424225 ns/op	    4612 B/op	      47 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-4            	     345	   3134850 ns/op	    4615 B/op	      48 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-8            	     309	   3787918 ns/op	    4616 B/op	      47 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-16           	     396	   3379008 ns/op	    4618 B/op	      47 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-24           	     285	   3766566 ns/op	    4623 B/op	      48 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-32           	     360	   3335844 ns/op	    4625 B/op	      48 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-64           	     390	   3076548 ns/op	    4632 B/op	      47 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-128          	     477	   2977945 ns/op	    4646 B/op	      47 allocs/op
BenchmarkConnectionPoolLightweightQuery_Single-256          	     511	   2371329 ns/op	    4741 B/op	      47 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel
BenchmarkConnectionPoolLightweightQuery_Parallel            	     538	   2752415 ns/op	    4613 B/op	      48 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-2          	     868	   1489619 ns/op	    4613 B/op	      48 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-4          	    1513	    690631 ns/op	    4643 B/op	      48 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-8          	    2557	    423272 ns/op	    4830 B/op	      50 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-16         	    4758	    295159 ns/op	    5276 B/op	      54 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-24         	    5086	    228114 ns/op	    5377 B/op	      55 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-32         	    7214	    165275 ns/op	    5474 B/op	      56 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-64         	    8224	    157339 ns/op	    5841 B/op	      59 allocs/op
BenchmarkConnectionPoolLightweightQuery_Parallel-128        	    6900	    206333 ns/op	    6483 B/op	      65 allocs/op
    BenchmarkConnectionPoolLightweightQuery_Parallel: benchmarks_test.go:32: read random number failed: rethinkdb: dial tcp 192.168.100.12:28015: connect: connection refused

and ran out of sockets

all the benchmarks done in real wifi-network without localhost rethinkdb

Under heavy load performance improved up to 4x times and memory consumption reduces up to 1.5x times.