netease-im / camellia

Camellia provide easy-to-use server toolkits, such as: redis proxy、delay queue、id gen、hot key and more
MIT License
601 stars 140 forks source link

Support Proxy to Redis Server connection pool #247

Closed segment11 closed 4 months ago

segment11 commented 5 months ago

Module: camellia-redis-proxy Content: As redis client send to redis server in pipeline mode, performance is much better. Can camellia-redis-proxy just use few connection to redis-server, send commands in batch?

Can blocking commands use this shared connection? Will latency decrease badly?

segment11 commented 5 months ago

Refer: pgbouncer

Lightweight connection pooler for PostgreSQL

caojiajun commented 5 months ago

explain in example

1、redis client send cmds [cmd1、cmd2、cmd3、cmd4、cmd5、cmd6] to proxy in pipeline 2、proxy will route to redis-server1 [cmd1、cmd3、cmd4] and redis-server2 [cmd2、cmd5、cmd6] in two connection in pipline in sharding logic( custom sharding or redis-cluster sharding)

caojiajun commented 5 months ago

1、non-blocking cmd will use the shared connection 2、blocking cmd will use the no-shared connection

segment11 commented 5 months ago

explain in example

1、redis client send cmds [cmd1、cmd2、cmd3、cmd4、cmd5、cmd6] to proxy in pipeline 2、proxy will route to redis-server1 [cmd1、cmd3、cmd4] and redis-server2 [cmd2、cmd5、cmd6] in two connection in pipline in sharding logic( custom sharding or redis-cluster sharding)

I've thought the first case,there ares 2 redis-clients (client A/client B send cmds to proxy (proxy A) not in pineline, client A send [cmd1、cmd2、cmd3], client B send [cmd4、cmd5、cmd6],can proxy A just send all thease commands [cmd1..cmd6] once in pineline to upstream redis-server A?

caojiajun commented 5 months ago

In earily version, proxy's logic is what you want, but it means proxy should use a queue to buffer cmds, and run in producter-consumer thread model, it will cause frequent context switching in the CPU