• <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)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜


            同樣在函數(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 在同一線程中,同一個連接conn上兩次創(chuàng)建的cur將會是一樣滴,因為是異步wait_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 放屁阿狗 閱讀(729) 評論(0)  編輯 收藏 引用 所屬分類: gevent
            7777精品伊人久久久大香线蕉 | 亚洲午夜久久久久久噜噜噜| 久久国产视屏| 四虎影视久久久免费观看| 久久强奷乱码老熟女网站| av午夜福利一片免费看久久| 99久久国产热无码精品免费久久久久| segui久久国产精品| 亚洲午夜精品久久久久久浪潮| 久久久久久精品成人免费图片| 久久久免费精品re6| 久久久久97国产精华液好用吗| 色青青草原桃花久久综合| 99麻豆久久久国产精品免费| 欧美一级久久久久久久大| 97久久精品午夜一区二区| 亚洲色欲久久久久综合网| 国产精品久久久久久吹潮| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 青春久久| 久久综合亚洲欧美成人| 国内精品久久久久国产盗摄| 少妇久久久久久被弄高潮| 日日狠狠久久偷偷色综合免费 | 久久免费香蕉视频| 久久久久亚洲av无码专区喷水| 久久综合给合综合久久| 国产精品成人无码久久久久久| 天天爽天天狠久久久综合麻豆 | 亚洲AV日韩精品久久久久| 欧美精品一区二区久久| 国产精品九九久久免费视频| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 亚洲国产天堂久久久久久| 国产综合免费精品久久久| 日本久久久精品中文字幕| 成人久久久观看免费毛片| 色综合久久久久久久久五月| 亚洲午夜无码久久久久| 人妻无码αv中文字幕久久| 综合网日日天干夜夜久久|