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

gunicorn_thrift block problem with high concurrency #52

Closed
zyi1992 opened this issue Nov 24, 2017 · 5 comments
Closed

gunicorn_thrift block problem with high concurrency #52

zyi1992 opened this issue Nov 24, 2017 · 5 comments

Comments

@zyi1992
Copy link

zyi1992 commented Nov 24, 2017

I was run thriftpy server as the readme suggest, and i used gunicorn_thrift as follow config

gunicorn_thrift account_server:app -w 60 \
  --worker-connections 2000 -k thriftpy_sync --thrift-protocol-factory thriftpy.protocol:TCyBinaryProtocolFactory \
    --thrift-transport-factory thriftpy.transport:TCyBufferedTransportFactory --threads 5  -D \
    --error-logfile /homex2/zhouyi/log/account_thrift_error.log --access-logfile /homex2/zhouyi/log/account_thrift_access.log\
      -b  0.0.0.0:16796 --reload  --forwarded-allow-ips 10.10.10.55

the test code was

import time
from multiprocessing import Process
import thriftpy
account_thrift = thriftpy.load("account.thrift", module_name="account_thrift")
from thriftpy.rpc import make_client

def main():
    thread_list = []
    start_time = time.time()
    for i in xrange(0,800):
        th = Process(target=process_func)
        th.start()
        thread_list.append(th)
    for i in thread_list:
        i.join()
    print time.time() - start_time

def process_func():
    th = MyThread()
    th.process_func()


class MyThread:
    def __init__(self):
        self.client = make_client(account_thrift.AccountRpc, '127.0.0.1', 16796)

    def process_func(self):
        for i in xrange(1,10000):
            print self.client.rpc_account_sid('account.5e4c769046c54b37a6f441fed028186d')
            time.sleep(0.5)


if __name__ == '__main__':
    r = main()

when i run the test code i got error with block
and i can't connect to the rpc server with other client too i got error
thriftpy.transport.TTransportException: TTransportException(message="Could not connect to ('127.0.0.1', 16796)", type=1)
, Is there any config error and what't the problem?

@zyi1992
Copy link
Author

zyi1992 commented Nov 24, 2017

it seems like the server workers was full with handle task , but this concurrence with 1600/s task rpc_account_sid would be return less than 1ms , so theoretically, the server can process more than
60000/s tasks, even there are network delay, the worker handle rate should be higher than 1600/s , glad for you replay.

@zyi1992
Copy link
Author

zyi1992 commented Nov 24, 2017

Things like to be work well when i change the -k parameter to thriftpy_gevent but i still get the point why i got the block, hope any explain

@aawilson
Copy link
Contributor

aawilson commented Dec 2, 2017

The -k parameter does not apply to sync workers in gunicorn, and the same applies to gunicorn_thrift (see here). Similarly, the --threads parameter only applies to threaded worker types (cite here), but that's also irrelevant because gunicorn_thrift hasn't implemented a gthread worker, so that isn't a supported argument anyway.

There's a pretty fundamental difference between sync workers and async workers (which, in this repo at this time, means gevent), so read up here to learn about what that is, so you can plan accordingly.

@wooparadog
Copy link
Member

@aawilson Thanks for answering!

The main reason is: sync worker can only handle 1 live connection per process. Currently gunicorn_thrift only supports gevent for high throughput scenarios.

We should implement thread worker, but I haven't got time to get down to it.

@zyi1992
Copy link
Author

zyi1992 commented Dec 4, 2017

Got it ,thanks for the explain!

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

No branches or pull requests

3 participants