Create a gist now

Instantly share code, notes, and snippets.

@tokibito /main.py
Last active Nov 24, 2016

thriftpy performance test
import thriftpy
from thriftpy.thrift import TProcessor
class AppServiceHandler:
def echo(self, message):
return message
main_thrift = thriftpy.load("main.thrift")
app = TProcessor(main_thrift.TIAppService, AppServiceHandler())
service TIAppService {
string echo(1: string message);
}
import thriftpy
from thriftpy.thrift import TProcessor
class AppServiceHandler:
def echo(self, message):
return message
main_thrift = thriftpy.load("main.thrift")
from thriftpy.rpc import make_server
server = make_server(main_thrift.TIAppService, AppServiceHandler(), '127.0.0.1', 8000)
server.serve()
import thriftpy
from thriftpy.rpc import make_client
main_thrift = thriftpy.load("main.thrift")
client = None
def call_proc():
msg = "hello"
result = client.echo(msg)
assert result == msg
def setup_client():
global client
client = make_client(main_thrift.TIAppService, host='127.0.0.1', port=8000)
if __name__ == '__main__':
import timeit
print(timeit.timeit("perf.call_proc()", setup="import perf; perf.setup_client()", number=10000))
thriftpy
gunicorn_thrift
# make_server
(venv) tokibito@ubuntu:~/sandbox/app$ python main_simple.py &
[1] 53556
(venv) tokibito@ubuntu:~/sandbox/app$ echo 1 2 3 4 |xargs -n 1 -P 4 python perf.py
3.171085872047115
3.2081114780157804
3.197533367027063
3.2391125739668496
(venv) tokibito@ubuntu:~/sandbox/app$ kill 53556
[1]+ Terminated python main_simple.py
# gunicorn
(venv) tokibito@ubuntu:~/sandbox/app$ gunicorn_thrift -w 4 -D main:app
(venv) tokibito@ubuntu:~/sandbox/app$ echo 1 2 3 4 |xargs -n 1 -P 4 python perf.py
3.327894259011373
3.3398498650058173
3.3992830860079266
3.392473387008067
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment