Last active
November 24, 2016 15:24
-
-
Save tokibito/4f0d0ff6c8f0dd4ee394eb28c88f3d50 to your computer and use it in GitHub Desktop.
thriftpy performance test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service TIAppService { | |
string echo(1: string message); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thriftpy | |
gunicorn_thrift |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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