Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Client Pool #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add Client Pool #5

wants to merge 2 commits into from

Conversation

bufferx
Copy link

@bufferx bufferx commented Apr 21, 2014

Usage

from toredis.pool import ClientPool

from tornado.gen import engine as gen_engine
from tornado.gen import Task as gen_Task

from tornado.ioloop import IOLoop

@gen_engine
def info():
    redis_pool = ClientPool(pool_size=20, host='127.0.0.1', port=6379)
    response = yield gen_Task(redis_pool.client.info)

    print response
    IOLoop.instance().stop()

info()
IOLoop.instance().start()

@mrjoes
Copy link
Owner

mrjoes commented Apr 21, 2014

I was thinking about connection pool before, but I don't see how it'll help and here's why:

  1. Redis is single threaded. It does not matter if there's one connection or multiple connections, it will execute commands one by one, sequentially. toredis is asynchronous redis client, you can send commands as fast as you want and whenever redis sends result back, your callbacks will be triggered;
  2. Pool adds complexity - some commands should lock connection in the pool and some should not.

Do you see any benefit to have a connection pool?

@bufferx
Copy link
Author

bufferx commented Apr 23, 2014

@mrjoes thanks for comment.

In my testing, connection pool will improve the performance when transfer large-byte data.
Statistical data as below:

8545cedc-378e-44b4-9fd6-4633d9d57150

We can see that 20-50% increase in TPS indicator, especially when dealing with large-byte data over the network, so I think the reason is

  1. Both of Tornado and Redis is single threaded. the entire data flow will be perform one by one in a unified channel, it can not process the next GET command generated by another HTTP REQUEST timely when transfer large-byte data which cause delay including network-delay, redis-self delay and tornado-self read delay.

  2. Multiple Connection make the processing of the entire data flow much more simultaneously, therefore reduce waiting for delay, and improve the indicator of transaction per second.

TEST DEMO: toredis_pool_test.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants