Python 壓力測試腳本

目的是寫個腳本,起多線程去call一個接口,來測試一個併發問題。

實現方案是將接口做到了一個頁面中,用python的http get請求來訪問查詢。

import urllib

import threading
from time import ctime,sleep



def t1(func):
  for i in range(10):
    f=urllib.urlopen("http://www.mystation.com/myinterface.html?param=value")
    s=f.read()
    print "round:%s, tread number:%s, returnValue:%s,time:%s" % (i, func, s, ctime())
    sleep(1)


if __name__ == '__main__':
  threads=[]
  for i in range(100):
    name = "t%s" % (i)
    name = threading.Thread(target=t1,args=(i,))
    threads.append(name)


  for t in threads:
    t.setDaemon(True)
    t.start()
  t.join()


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章