• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            socketref,再見!高德

            https://github.com/adoggie

              C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              246 Posts :: 4 Stories :: 312 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(54)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜


            同樣在函數(shù)中連接pgsql,然后執(zhí)行500次查詢,
            測試gevent模式、串行查詢、多線程查詢
            數(shù)據(jù)如下: 
            multithread_test cost time: 2.45199990273
            normal_test cost time: 4.04299998283
            gevent_test cost time: 2.12800002098
            結(jié)果 串行最慢4.4s, 多線程 2.45s ,gevent最快2.12 ,yes!

            測試代碼: 
             1 import gevent
             2 import gevent.queue
             3 
             4 import psycopg2
             5 import psycopg2.extensions
             6 
             7 import psycogreen.gevent
             8 
             9 psycogreen.gevent.patch_psycopg()
            10 
            11 sys.path.insert(0,'../')
            12 
            13 import easymq
            14 
            15 '''
            16 在同一線程中,同一個(gè)連接conn上兩次創(chuàng)建的cur將會是一樣滴,因?yàn)槭钱惒絯ait_read()緣故
            17 所以要么每次創(chuàng)建數(shù)據(jù)庫連接,要么使用dbpool
            18 '''
            19 
            20 
            21 def readThread():
            22     conn = psycopg2.connect(database='postgres',user='postgres',password='111111')
            23 
            24     # cur = conn.cursor(cursor_factory=psycopg2.extensions.DictCursor)
            25     cur = conn.cursor(cursor_factory=psycopg2.extensions.cursor)
            26 
            27     # cur.execute("select pg_sleep(%s)", (2,))
            28     for n in range(10):
            29         cur.execute("select CURRENT_DATE")
            30         # print cur.fetchone()
            31     # print 'read end..'
            32     conn = None
            33 
            34 
            35 def gevent_test():
            36     jobs=[]
            37     for n in range(100):
            38         jobs.append(gevent.spawn(readThread))
            39     gevent.joinall(jobs)
            40 
            41 def normal_test():
            42     for n in range(100):
            43         readThread()
            44 
            45 def multithread_test():
            46     threads=[]
            47     for n in range(100):
            48         thread = threading.Thread(target=readThread)
            49         threads.append(thread)
            50         thread.start()
            51     for thread in threads:
            52         thread.join()
            53 
            54 start = time.time()
            55 normal_test()
            56 end = time.time()
            57 print 'normal_test cost time:',end-start
            58 
            59 start = time.time()
            60 gevent_test()
            61 end = time.time()
            62 print 'gevent_test cost time:',end-start
            63 
            64 # start = time.time()
            65 # multithread_test()
            66 # end = time.time()
            67 # print 'multithread_test cost time:',end-start
            68 
            posted on 2013-09-25 02:08 放屁阿狗 閱讀(731) 評論(0)  編輯 收藏 引用 所屬分類: gevent
            久久精品亚洲精品国产色婷 | 久久综合亚洲欧美成人| 久久精品中文闷骚内射| 91精品国产综合久久婷婷| 色8激情欧美成人久久综合电| 麻豆av久久av盛宴av| 国产精品久久久久aaaa| 久久播电影网| 久久精品9988| 日韩精品久久无码中文字幕| 日本免费久久久久久久网站| 亚洲国产精品18久久久久久| 香蕉久久久久久狠狠色| 香港aa三级久久三级| 色综合久久久久网| 精品熟女少妇AV免费久久| 一级a性色生活片久久无少妇一级婬片免费放 | 99久久夜色精品国产网站| 国内精品久久久久久99| 香蕉久久夜色精品升级完成| 久久精品不卡| 久久伊人影视| 久久亚洲中文字幕精品一区四| 久久精品水蜜桃av综合天堂| 奇米影视7777久久精品人人爽| 91精品国产91久久久久久| 成人综合伊人五月婷久久| 国内高清久久久久久| 99久久国产综合精品女同图片| 久久免费视频一区| 国产精品日韩深夜福利久久| 久久99精品国产一区二区三区| 欧美日韩精品久久久久| 欧美一区二区久久精品| 久久性生大片免费观看性| 精品久久国产一区二区三区香蕉 | 欧美喷潮久久久XXXXx| 精品久久久无码人妻中文字幕| 热99RE久久精品这里都是精品免费| 色天使久久综合网天天| 午夜视频久久久久一区|