Differences between revisions 1 and 2
Revision 1 as of 2007-07-16 02:36:44
Size: 3564
Editor: ZoomQuiet
Comment:
Revision 2 as of 2007-07-16 02:49:17
Size: 5436
Editor: ZoomQuiet
Comment: fixed export
Deletions are marked like this. Additions are marked like this.
Line 96: Line 96:
       print '\xb2\xe2\xca\xd4\xcd\xea\xb3\xc9:\xd7\xdc\xd3\xc3\xca\xb1 %f
s' %(totleTime)
       print '\xb2\xe2\xca\xd4\xb4\xce\xca\xfd: %d \xb2\xa2\xb7\xa2\xc7\xeb
\xc7\xf3: %d'%(times,threadNum)
       print '\xc6\xbd\xbe\xf9\xc3\xbf\xb4\xce\xd3\xc3\xca\xb1 %f s'%
(totleTime/times)
       print '\xd7\xee\xb4\xf3\xd3\xc3\xca\xb1: %f s \xd7\xee
\xd0\xa1\xd3\xc3\xca\xb1 %f s'%(maxTime,minTime)
       print '\xc3\xbf\xc3\xeb\xcf\xec\xd3\xa6\xca\xfd:%f'%(times/totleTime)
       print '\xbd\xf8\xd0\xd0\xc1\xcb %d \xb4\xce set \xb2\xd9\xd7\xf7'%
(opList[0])
       print '\xbd\xf8\xd0\xd0\xc1\xcb %d \xb4\xce get \xb2\xd9\xd7\xf7'%
(opList[1])
       print '\xbd\xf8\xd0\xd0\xc1\xcb %d \xb4\xce delete \xb2\xd9\xd7\xf7'%
(opList[2])
import memcache
import threading
import time
import random
import sys

serverList = ['192.168.21.106:11211']
dIndexRange = 1000 #测试数据的下标范围
keyPre = 'TestKey_%d'#测试数据Key前缀
dataSize = 512 #每条测试数据 大小

#test result
totleTime = 0
times = 0
avgTime = 0
minTime = 0
maxTime = 0
rePerS = 0 #每秒相应数
opList = [0,0,0] #读,写,删次数
myLock = threading.RLock()

class testThread(threading.Thread):
       def __init__(self,tName='testMemcached'):
               threading.Thread.__init__(self,name=tName)

       def run(self):
               global serverList,dIndexRange,keyPre,dataSize
               global totleTime,times,avgTime,minTime,maxTime,rePerS,myLock

               mc = memcache.Client(serverList,debug=0)
               #随机操作类型和下标
               opType = random.randrange(0,3)
               opKey = random.randrange(0,dIndexRange)
               opKey = keyPre%(opKey)
               #初始数据
               opData = []
               for i in range(dataSize):
                       opData.append(i)

       startTime = time.time()
               if opType == 0:
                       mc.set(opKey,opData)
               elif opType == 1:
                       mc.get(opKey)
               elif opType == 2:
                       opresult = mc.delete(opKey)
               endTime = time.time()
               opTime = endTime - startTime

               myLock.acquire()
               opList[opType] = opList[opType] + 1
               print opTime
               totleTime = totleTime + opTime
               if minTime == 0 or opTime < minTime:
                       minTime = opTime
               if maxTime == 0 or maxTime < opTime:
                       maxTime = opTime

               myLock.release()
               mc.disconnect_all()


times = int(sys.argv[1])
threadNum = int(sys.argv[2])

for i in range(times):
       while threading.activeCount()>threadNum:
               time.sleep(0.1)
       else:
               testThread().start()

while threading.activeCount()>1:
       time.sleep(2)
else:
       print 'Total used time: %f s' %(totleTime)
       print 'Send request: %d simultaneities: %d'%(times,threadNum)
       print 'Avarage time %f s'%(totleTime/times)
       print 'MaxTime: %f s MinTime %f s'%(maxTime,minTime)
       print 'Requests Per Second:%f'%(times/totleTime)
       print 'Set operations: %d '%(opList[0])
       print 'Get operations: %d '%(opList[1])
       print 'Delete operations: %d'%(opList[2])

memcached的压力测试 ::-- ZoomQuiet [DateTime(2007-07-16T02:36:44Z)] TableOfContents

Include(CPUGnav)

1. memcached压力测试

{{{"John.H" <[email protected]> hide details 9:55 am (1 minute ago)

  • reply-to [email protected] to "python.cn" <[email protected]> date Jul 16, 2007 9:55 AM subject [CPyUG:29059] 用python写了一个memcached的压力测试程序,望大家指点 mailed-by googlegroups.com

}}}

   1 import memcache
   2 import threading
   3 import time
   4 import random
   5 import sys
   6 
   7 serverList = ['192.168.21.106:11211']
   8 dIndexRange = 1000 #测试数据的下标范围
   9 keyPre = 'TestKey_%d'#测试数据Key前缀
  10 dataSize = 512 #每条测试数据 大小
  11 
  12 #test result
  13 totleTime = 0
  14 times = 0
  15 avgTime = 0
  16 minTime = 0
  17 maxTime = 0
  18 rePerS = 0 #每秒相应数
  19 opList = [0,0,0] #读,写,删次数
  20 myLock = threading.RLock()
  21 
  22 class testThread(threading.Thread):
  23        def __init__(self,tName='testMemcached'):
  24                threading.Thread.__init__(self,name=tName)
  25 
  26        def run(self):
  27                global serverList,dIndexRange,keyPre,dataSize
  28                global totleTime,times,avgTime,minTime,maxTime,rePerS,myLock
  29 
  30                mc = memcache.Client(serverList,debug=0)
  31                #随机操作类型和下标
  32                opType = random.randrange(0,3)
  33                opKey = random.randrange(0,dIndexRange)
  34                opKey = keyPre%(opKey)
  35                #初始数据
  36                opData = []
  37                for i in range(dataSize):
  38                        opData.append(i)
  39 
  40                startTime = time.time()
  41                if opType == 0:
  42                        mc.set(opKey,opData)
  43                elif opType == 1:
  44                        mc.get(opKey)
  45                elif opType == 2:
  46                        opresult = mc.delete(opKey)
  47                endTime = time.time()
  48                opTime = endTime - startTime
  49 
  50                myLock.acquire()
  51                opList[opType] = opList[opType] + 1
  52                print opTime
  53                totleTime = totleTime + opTime
  54                if minTime == 0 or opTime < minTime:
  55                        minTime = opTime
  56                if maxTime == 0 or maxTime < opTime:
  57                        maxTime = opTime
  58 
  59                myLock.release()
  60                mc.disconnect_all()
  61 
  62 
  63 times = int(sys.argv[1])
  64 threadNum = int(sys.argv[2])
  65 
  66 for i in range(times):
  67        while threading.activeCount()>threadNum:
  68                time.sleep(0.1)
  69        else:
  70                testThread().start()
  71 
  72 while threading.activeCount()>1:
  73        time.sleep(2)
  74 else:
  75 import memcache
  76 import threading
  77 import time
  78 import random
  79 import sys
  80 
  81 serverList = ['192.168.21.106:11211']
  82 dIndexRange = 1000 #测试数据的下标范围
  83 keyPre = 'TestKey_%d'#测试数据Key前缀
  84 dataSize = 512 #每条测试数据 大小
  85 
  86 #test result
  87 totleTime = 0
  88 times = 0
  89 avgTime = 0
  90 minTime = 0
  91 maxTime = 0
  92 rePerS = 0 #每秒相应数
  93 opList = [0,0,0] #读,写,删次数
  94 myLock = threading.RLock()
  95 
  96 class testThread(threading.Thread):
  97        def __init__(self,tName='testMemcached'):
  98                threading.Thread.__init__(self,name=tName)
  99 
 100        def run(self):
 101                global serverList,dIndexRange,keyPre,dataSize
 102                global totleTime,times,avgTime,minTime,maxTime,rePerS,myLock
 103 
 104                mc = memcache.Client(serverList,debug=0)
 105                #随机操作类型和下标
 106                opType = random.randrange(0,3)
 107                opKey = random.randrange(0,dIndexRange)
 108                opKey = keyPre%(opKey)
 109                #初始数据
 110                opData = []
 111                for i in range(dataSize):
 112                        opData.append(i)
 113 
 114        startTime = time.time()
 115                if opType == 0:
 116                        mc.set(opKey,opData)
 117                elif opType == 1:
 118                        mc.get(opKey)
 119                elif opType == 2:
 120                        opresult = mc.delete(opKey)
 121                endTime = time.time()
 122                opTime = endTime - startTime
 123 
 124                myLock.acquire()
 125                opList[opType] = opList[opType] + 1
 126                print opTime
 127                totleTime = totleTime + opTime
 128                if minTime == 0 or opTime < minTime:
 129                        minTime = opTime
 130                if maxTime == 0 or maxTime < opTime:
 131                        maxTime = opTime
 132 
 133                myLock.release()
 134                mc.disconnect_all()
 135 
 136 
 137 times = int(sys.argv[1])
 138 threadNum = int(sys.argv[2])
 139 
 140 for i in range(times):
 141        while threading.activeCount()>threadNum:
 142                time.sleep(0.1)
 143        else:
 144                testThread().start()
 145 
 146 while threading.activeCount()>1:
 147        time.sleep(2)
 148 else:
 149        print 'Total used time: %f s' %(totleTime)
 150        print 'Send request: %d simultaneities: %d'%(times,threadNum)
 151        print 'Avarage time %f s'%(totleTime/times)
 152        print 'MaxTime: %f s    MinTime %f s'%(maxTime,minTime)
 153        print 'Requests Per Second:%f'%(times/totleTime)
 154        print 'Set operations: %d '%(opList[0])
 155        print 'Get operations: %d '%(opList[1])
 156        print 'Delete operations: %d'%(opList[2])

1.1. 反馈

PageComment2

MicroProj/2007-07-16 (last edited 2009-12-25 07:12:50 by localhost)