Python實現(xiàn)的多線程http壓力測試代碼
本文實例講述了Python實現(xiàn)的多線程http壓力測試代碼。分享給大家供大家參考,具體如下:
# Python version 3.3 __author__ = 'Toil' import sys, getopt import threading def httpGet(url, file): import http.client conn = http.client.HTTPConnection(url) conn.request("GET", file) r = conn.getresponse() #print(r.getheaders()) while not r.closed: r.read(200) conn.close() def Usage(): print(''' Options are: -c concurrency Number of multiple requests to make -u host The host -f file File on web Example: httpget.py -c 100 -u www.example.com -f / ''') if __name__ == '__main__': opts, args = getopt.getopt(sys.argv[1:], "hc:u:f:") global u, c, f for op, value in opts: if op == '-c': c = int(value) elif op == '-u': u = value elif op == '-f': f = value elif op == '-h': Usage() sys.exit(0) else: sys.exit(0) threads = [] times = c print('Test for ', u, f) print('waiting...') for i in range(0, times): t = threading.Thread(target=httpGet(u, f)) threads.append(t) for i in range(0, times): threads[i].start() for i in range(0, times): threads[i].join()
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python URL操作技巧總結(jié)》、《Python Socket編程技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
Django中日期時間型字段進(jìn)行年月日時分秒分組統(tǒng)計
這篇文章主要介紹了Django中日期時間型字段進(jìn)行年月日時分秒分組統(tǒng)計,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11python中使用百度音樂搜索的api下載指定歌曲的lrc歌詞
這篇文章主要介紹了python中使用百度音樂搜索的api下載指定歌曲的lrc歌詞,同時也分析出了歌曲的下載地址,需要的朋友可以參考下2014-07-07Pandas如何將Timestamp轉(zhuǎn)為datetime類型
這篇文章主要介紹了Pandas如何將Timestamp轉(zhuǎn)為datetime類型,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07Python matplotlib 畫圖窗口顯示到gui或者控制臺的實例
今天小編就為大家分享一篇Python matplotlib 畫圖窗口顯示到gui或者控制臺的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-05-05python實現(xiàn)數(shù)通設(shè)備端口監(jiān)控示例
這篇文章主要介紹了python實現(xiàn)數(shù)通設(shè)備端口監(jiān)控示例,需要的朋友可以參考下2014-04-04