作家
登录

使用Python提供高性能计算服务

作者: 来源: 2017-05-25 13:02:26 阅读 我要评论

  •     logging.info('[handle_api_foo] val: %d' % (val)) 
  •     #do calc 
  •     result = fooWrapper.foo(val) 
  •     logging.info('[handle_api_foo] result: %d' % (result)) 
  •     result = json.dumps({'result':result}) 
  •     return result 
  • 单查究事

    起首测试python单查究事,同时也是单线程办事(因为python GIL的存在,python多线程对于计算密集型义务几乎起反感化)。

    • 启动办事
    1. #!/bin/sh 
    2. #python 
    3. export PYTHONIOENCODING=utf-8 
    4. #start server 
    5. cd `pwd`/.. 
    6. echo "run single pocess server" 
    7. python server.py 
    8. cd - 
    9. echo "server is started." 
    • 测试办事

    别的打开一个终端,履行script目次下的bench.sh,即

    1. #!/bin/sh 
    2. ab -T 'application/json' -p post.data -n 100 -c 10 http://127.0.0.1:4096/api/foo 
    • 测试结不雅

    总结

    CPU运转

    ab测试结不雅

    可以看出CPU只用了1个核,负载是2.44 request/second。

    多核

    • 启动办事

    在script目次下履行run_parallel.sh,即

    1. #!/bin/sh 
    2. #python 
    3. export PYTHONIOENCODING=utf-8 
    4. #start server 
    5. cd `pwd`/.. 
    6. echo "run parallel pocess server" 
    7. gunicorn -c gun.conf server:app 
    8. cd - 
    9. echo "server is started." 

    个中gun.conf是一个python脚本,设备了gunicorn的一些参数,如下:

    1. import multiprocessing 
    2. bind = '0.0.0.0:4096' 
    3. workers = max(multiprocessing.cpu_count()*2+1,1) 
    4. backlog = 2048 
    5. worker_class = "sync" 
    6. debug = False 
    7. proc_name = 'foo_server' 
    • 测试办事

    别的打开一个终端,履行script目次下的bench.sh,即

    1. #!/bin/sh 
    2. ab -T 'application/json' -p post.data -n 100 -c 10 http://127.0.0.1:4096/api/foo 
    • 测试结不雅

    CPU运转

    ab测试结不雅

    可以看出CPU用满了4个核,负载是8.56 request/second。是单核的3.5倍阁下,可以义务根本杀青多核有效应用的的目标。


      推荐阅读

      如何理解5G空口(NR)?

    电信行业肯定欲望在超高容量和低延迟的下一代收集的支撑下安排5G营业,然则在5G商用之前,该技巧须要做进一步>>>详细阅读


    本文标题:使用Python提供高性能计算服务

    地址:http://www.17bianji.com/lsqh/35421.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)