[Zope-Checkins] CVS: Zope2 - asyn_http_bench.py:1.3 max_sockets.py:1.4 test_11.py:1.3 test_lb.py:1.3 test_medusa.py:1.3 test_single_11.py:1.3
andreas@serenade.digicool.com
andreas@serenade.digicool.com
Tue, 1 May 2001 07:45:58 -0400
Update of /cvs-repository/Zope2/ZServer/medusa/test
In directory serenade.digicool.com:/tmp/cvs-serv12359/test
Modified Files:
asyn_http_bench.py max_sockets.py test_11.py test_lb.py
test_medusa.py test_single_11.py
Log Message:
we *hate* tabs - lets get rid of them
--- Updated File asyn_http_bench.py in package Zope2 --
--- asyn_http_bench.py 2001/04/25 19:09:55 1.2
+++ asyn_http_bench.py 2001/05/01 11:45:27 1.3
@@ -7,92 +7,92 @@
import sys
def blurt (thing):
- sys.stdout.write (thing)
- sys.stdout.flush ()
-
+ sys.stdout.write (thing)
+ sys.stdout.flush ()
+
total_sessions = 0
class http_client (asyncore.dispatcher_with_send):
- def __init__ (self, host='127.0.0.1', port=80, uri='/', num=10):
- asyncore.dispatcher_with_send.__init__ (self)
- self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
- self.host = host
- self.port = port
- self.uri = uri
- self.num = num
- self.bytes = 0
- self.connect ((host, port))
-
- def log (self, *info):
- pass
-
- def handle_connect (self):
- self.connected = 1
-# blurt ('o')
- self.send ('GET %s HTTP/1.0\r\n\r\n' % self.uri)
-
- def handle_read (self):
-# blurt ('.')
- d = self.recv (8192)
- self.bytes = self.bytes + len(d)
-
- def handle_close (self):
- global total_sessions
-# blurt ('(%d)' % (self.bytes))
- self.close()
- total_sessions = total_sessions + 1
- if self.num:
- http_client (self.host, self.port, self.uri, self.num-1)
-
+ def __init__ (self, host='127.0.0.1', port=80, uri='/', num=10):
+ asyncore.dispatcher_with_send.__init__ (self)
+ self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
+ self.host = host
+ self.port = port
+ self.uri = uri
+ self.num = num
+ self.bytes = 0
+ self.connect ((host, port))
+
+ def log (self, *info):
+ pass
+
+ def handle_connect (self):
+ self.connected = 1
+ # blurt ('o')
+ self.send ('GET %s HTTP/1.0\r\n\r\n' % self.uri)
+
+ def handle_read (self):
+ # blurt ('.')
+ d = self.recv (8192)
+ self.bytes = self.bytes + len(d)
+
+ def handle_close (self):
+ global total_sessions
+ # blurt ('(%d)' % (self.bytes))
+ self.close()
+ total_sessions = total_sessions + 1
+ if self.num:
+ http_client (self.host, self.port, self.uri, self.num-1)
+
import time
class timer:
- def __init__ (self):
- self.start = time.time()
- def end (self):
- return time.time() - self.start
-
+ def __init__ (self):
+ self.start = time.time()
+ def end (self):
+ return time.time() - self.start
+
from asyncore import socket_map, poll
MAX = 0
def loop (timeout=30.0):
- global MAX
- while socket_map:
- if len(socket_map) > MAX:
- MAX = len(socket_map)
- poll (timeout)
-
+ global MAX
+ while socket_map:
+ if len(socket_map) > MAX:
+ MAX = len(socket_map)
+ poll (timeout)
+
if __name__ == '__main__':
- if len(sys.argv) < 6:
- print 'usage: %s <host> <port> <uri> <hits> <num_clients>' % sys.argv[0]
- else:
- [host, port, uri, hits, num] = sys.argv[1:]
- hits = string.atoi (hits)
- num = string.atoi (num)
- port = string.atoi (port)
- t = timer()
- clients = map (lambda x: http_client (host, port, uri, hits-1), range(num))
- #import profile
- #profile.run ('loop')
- loop()
- total_time = t.end()
- print (
- '\n%d clients\n%d hits/client\n'
- 'total_hits:%d\n%.3f seconds\ntotal hits/sec:%.3f' % (
- num,
- hits,
- total_sessions,
- total_time,
- total_sessions / total_time
- )
- )
- print 'Max. number of concurrent sessions: %d' % (MAX)
-
-
-# linux 2.x, talking to medusa
-# 50 clients
-# 1000 hits/client
-# total_hits:50000
-# 2255.858 seconds
-# total hits/sec:22.165
-# Max. number of concurrent sessions: 50
+ if len(sys.argv) < 6:
+ print 'usage: %s <host> <port> <uri> <hits> <num_clients>' % sys.argv[0]
+ else:
+ [host, port, uri, hits, num] = sys.argv[1:]
+ hits = string.atoi (hits)
+ num = string.atoi (num)
+ port = string.atoi (port)
+ t = timer()
+ clients = map (lambda x: http_client (host, port, uri, hits-1), range(num))
+ #import profile
+ #profile.run ('loop')
+ loop()
+ total_time = t.end()
+ print (
+ '\n%d clients\n%d hits/client\n'
+ 'total_hits:%d\n%.3f seconds\ntotal hits/sec:%.3f' % (
+ num,
+ hits,
+ total_sessions,
+ total_time,
+ total_sessions / total_time
+ )
+ )
+ print 'Max. number of concurrent sessions: %d' % (MAX)
+
+
+ # linux 2.x, talking to medusa
+ # 50 clients
+ # 1000 hits/client
+ # total_hits:50000
+ # 2255.858 seconds
+ # total hits/sec:22.165
+ # Max. number of concurrent sessions: 50
--- Updated File max_sockets.py in package Zope2 --
--- max_sockets.py 2001/04/30 19:55:30 1.3
+++ max_sockets.py 2001/05/01 11:45:27 1.4
@@ -9,57 +9,57 @@
# 4) max we can connect
def max_server_sockets():
- sl = []
- while 1:
- try:
- s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- s.bind (('',0))
- s.listen(5)
- sl.append (s)
- except:
- break
- num = len(sl)
- for s in sl:
- s.close()
- del sl
- return num
-
+ sl = []
+ while 1:
+ try:
+ s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
+ s.bind (('',0))
+ s.listen(5)
+ sl.append (s)
+ except:
+ break
+ num = len(sl)
+ for s in sl:
+ s.close()
+ del sl
+ return num
+
def max_client_sockets():
- # make a server socket
- server = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- server.bind (('', 9999))
- server.listen (5)
- sl = []
- while 1:
- try:
- s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- s.connect (('', 9999))
- conn, addr = server.accept()
- sl.append ((s,conn))
- except:
- break
- num = len(sl)
- for s,c in sl:
- s.close()
- c.close()
- del sl
- return num
-
+ # make a server socket
+ server = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
+ server.bind (('', 9999))
+ server.listen (5)
+ sl = []
+ while 1:
+ try:
+ s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
+ s.connect (('', 9999))
+ conn, addr = server.accept()
+ sl.append ((s,conn))
+ except:
+ break
+ num = len(sl)
+ for s,c in sl:
+ s.close()
+ c.close()
+ del sl
+ return num
+
def max_select_sockets():
- sl = []
- while 1:
- try:
- num = len(sl)
- for i in range(1 + len(sl) * 0.05):
- # Increase exponentially.
- s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- s.bind (('',0))
- s.listen(5)
- sl.append (s)
- select.select(sl,[],[],0)
- except:
- break
- for s in sl:
- s.close()
- del sl
- return num
+ sl = []
+ while 1:
+ try:
+ num = len(sl)
+ for i in range(1 + len(sl) * 0.05):
+ # Increase exponentially.
+ s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
+ s.bind (('',0))
+ s.listen(5)
+ sl.append (s)
+ select.select(sl,[],[],0)
+ except:
+ break
+ for s in sl:
+ s.close()
+ del sl
+ return num
--- Updated File test_11.py in package Zope2 --
--- test_11.py 2001/04/25 19:09:55 1.2
+++ test_11.py 2001/05/01 11:45:27 1.3
@@ -10,101 +10,101 @@
class test_client (asynchat.async_chat):
- ac_in_buffer_size = 16384
- ac_out_buffer_size = 16384
-
- total_in = 0
-
- concurrent = 0
- max_concurrent = 0
-
- def __init__ (self, addr, chain):
- asynchat.async_chat.__init__ (self)
- self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
- self.set_terminator ('\r\n\r\n')
- self.connect (addr)
- self.push (chain)
-
- def handle_connect (self):
- test_client.concurrent = test_client.concurrent + 1
- if (test_client.concurrent > test_client.max_concurrent):
- test_client.max_concurrent = test_client.concurrent
-
- def handle_expt (self):
- print 'unexpected FD_EXPT thrown. closing()'
- self.close()
-
- def close (self):
- test_client.concurrent = test_client.concurrent - 1
- asynchat.async_chat.close(self)
-
- def collect_incoming_data (self, data):
- test_client.total_in = test_client.total_in + len(data)
-
- def found_terminator (self):
- pass
-
- def log (self, *args):
- pass
-
-
+ ac_in_buffer_size = 16384
+ ac_out_buffer_size = 16384
+
+ total_in = 0
+
+ concurrent = 0
+ max_concurrent = 0
+
+ def __init__ (self, addr, chain):
+ asynchat.async_chat.__init__ (self)
+ self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
+ self.set_terminator ('\r\n\r\n')
+ self.connect (addr)
+ self.push (chain)
+
+ def handle_connect (self):
+ test_client.concurrent = test_client.concurrent + 1
+ if (test_client.concurrent > test_client.max_concurrent):
+ test_client.max_concurrent = test_client.concurrent
+
+ def handle_expt (self):
+ print 'unexpected FD_EXPT thrown. closing()'
+ self.close()
+
+ def close (self):
+ test_client.concurrent = test_client.concurrent - 1
+ asynchat.async_chat.close(self)
+
+ def collect_incoming_data (self, data):
+ test_client.total_in = test_client.total_in + len(data)
+
+ def found_terminator (self):
+ pass
+
+ def log (self, *args):
+ pass
+
+
import time
class timer:
- def __init__ (self):
- self.start = time.time()
-
- def end (self):
- return time.time() - self.start
-
+ def __init__ (self):
+ self.start = time.time()
+
+ def end (self):
+ return time.time() - self.start
+
def build_request_chain (num, host, request_size):
- s = 'GET /test%d.html HTTP/1.1\r\nHost: %s\r\n\r\n' % (request_size, host)
- sl = [s] * (num-1)
- sl.append (
- 'GET /test%d.html HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n' % (
- request_size, host
- )
- )
- return string.join (sl, '')
-
+ s = 'GET /test%d.html HTTP/1.1\r\nHost: %s\r\n\r\n' % (request_size, host)
+ sl = [s] * (num-1)
+ sl.append (
+ 'GET /test%d.html HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n' % (
+ request_size, host
+ )
+ )
+ return string.join (sl, '')
+
if __name__ == '__main__':
- import string
- import sys
- if len(sys.argv) != 6:
- print 'usage: %s <host> <port> <request-size> <num-requests> <num-connections>\n' % sys.argv[0]
- else:
- host = sys.argv[1]
-
- ip = socket.gethostbyname (host)
-
- [port, request_size, num_requests, num_conns] = map (
- string.atoi, sys.argv[2:]
- )
-
- chain = build_request_chain (num_requests, host, request_size)
-
- t = timer()
- for i in range (num_conns):
- test_client ((host,port), chain)
- asyncore.loop()
- total_time = t.end()
-
- # ok, now do some numbers
- total_bytes = test_client.total_in
- num_trans = num_requests * num_conns
- throughput = float (total_bytes) / total_time
- trans_per_sec = num_trans / total_time
-
- sys.stderr.write ('total time: %.2f\n' % total_time)
- sys.stderr.write ('number of transactions: %d\n' % num_trans)
- sys.stderr.write ('total bytes sent: %d\n' % total_bytes)
- sys.stderr.write ('total throughput (bytes/sec): %.2f\n' % throughput)
- sys.stderr.write ('transactions/second: %.2f\n' % trans_per_sec)
- sys.stderr.write ('max concurrent connections: %d\n' % test_client.max_concurrent)
-
- sys.stdout.write (
- string.join (
- map (str, (num_conns, num_requests, request_size, throughput, trans_per_sec)),
- ','
- ) + '\n'
- )
+ import string
+ import sys
+ if len(sys.argv) != 6:
+ print 'usage: %s <host> <port> <request-size> <num-requests> <num-connections>\n' % sys.argv[0]
+ else:
+ host = sys.argv[1]
+
+ ip = socket.gethostbyname (host)
+
+ [port, request_size, num_requests, num_conns] = map (
+ string.atoi, sys.argv[2:]
+ )
+
+ chain = build_request_chain (num_requests, host, request_size)
+
+ t = timer()
+ for i in range (num_conns):
+ test_client ((host,port), chain)
+ asyncore.loop()
+ total_time = t.end()
+
+ # ok, now do some numbers
+ total_bytes = test_client.total_in
+ num_trans = num_requests * num_conns
+ throughput = float (total_bytes) / total_time
+ trans_per_sec = num_trans / total_time
+
+ sys.stderr.write ('total time: %.2f\n' % total_time)
+ sys.stderr.write ('number of transactions: %d\n' % num_trans)
+ sys.stderr.write ('total bytes sent: %d\n' % total_bytes)
+ sys.stderr.write ('total throughput (bytes/sec): %.2f\n' % throughput)
+ sys.stderr.write ('transactions/second: %.2f\n' % trans_per_sec)
+ sys.stderr.write ('max concurrent connections: %d\n' % test_client.max_concurrent)
+
+ sys.stdout.write (
+ string.join (
+ map (str, (num_conns, num_requests, request_size, throughput, trans_per_sec)),
+ ','
+ ) + '\n'
+ )
--- Updated File test_lb.py in package Zope2 --
--- test_lb.py 2001/04/25 19:09:55 1.2
+++ test_lb.py 2001/05/01 11:45:27 1.3
@@ -18,142 +18,142 @@
class test_channel (asynchat.async_chat):
- ac_in_buffer_size = 16384
- ac_out_buffer_size = 16384
-
- total_in = 0
-
- def __init__ (self, conn, addr):
- asynchat.async_chat.__init__ (self, conn)
- self.set_terminator ('\r\n\r\n')
- self.buffer = ''
-
- def collect_incoming_data (self, data):
- self.buffer = self.buffer + data
- test_channel.total_in = test_channel.total_in + len(data)
-
- def found_terminator (self):
- # we've gotten the data, now send it back
- data = self.buffer
- self.buffer = ''
- self.push (data+'\r\n\r\n')
-
- def handle_close (self):
- sys.stdout.write ('.'); sys.stdout.flush()
- self.close()
-
- def log (self, *args):
- pass
-
+ ac_in_buffer_size = 16384
+ ac_out_buffer_size = 16384
+
+ total_in = 0
+
+ def __init__ (self, conn, addr):
+ asynchat.async_chat.__init__ (self, conn)
+ self.set_terminator ('\r\n\r\n')
+ self.buffer = ''
+
+ def collect_incoming_data (self, data):
+ self.buffer = self.buffer + data
+ test_channel.total_in = test_channel.total_in + len(data)
+
+ def found_terminator (self):
+ # we've gotten the data, now send it back
+ data = self.buffer
+ self.buffer = ''
+ self.push (data+'\r\n\r\n')
+
+ def handle_close (self):
+ sys.stdout.write ('.'); sys.stdout.flush()
+ self.close()
+
+ def log (self, *args):
+ pass
+
class test_server (asyncore.dispatcher):
- def __init__ (self, addr):
-
- if type(addr) == type(''):
- f = socket.AF_UNIX
- else:
- f = socket.AF_INET
-
- self.create_socket (f, socket.SOCK_STREAM)
- self.bind (addr)
- self.listen (5)
- print 'server started on',addr
-
- def handle_accept (self):
- conn, addr = self.accept()
- test_channel (conn, addr)
-
-# ==================================================
-# client
-# ==================================================
-
-# pretty much the same behavior, except that we kick
-# off the exchange and decide when to quit
-
+ def __init__ (self, addr):
+
+ if type(addr) == type(''):
+ f = socket.AF_UNIX
+ else:
+ f = socket.AF_INET
+
+ self.create_socket (f, socket.SOCK_STREAM)
+ self.bind (addr)
+ self.listen (5)
+ print 'server started on',addr
+
+ def handle_accept (self):
+ conn, addr = self.accept()
+ test_channel (conn, addr)
+
+ # ==================================================
+ # client
+ # ==================================================
+
+ # pretty much the same behavior, except that we kick
+ # off the exchange and decide when to quit
+
class test_client (test_channel):
- def __init__ (self, addr, packet, number):
- if type(addr) == type(''):
- f = socket.AF_UNIX
- else:
- f = socket.AF_INET
-
- asynchat.async_chat.__init__ (self)
- self.create_socket (f, socket.SOCK_STREAM)
- self.set_terminator ('\r\n\r\n')
- self.buffer = ''
- self.connect (addr)
- self.push (packet + '\r\n\r\n')
- self.number = number
- self.count = 0
-
- def handle_connect (self):
- pass
-
- def found_terminator (self):
- self.count = self.count + 1
- if self.count == self.number:
- sys.stdout.write('.'); sys.stdout.flush()
- self.close()
- else:
- test_channel.found_terminator (self)
-
+ def __init__ (self, addr, packet, number):
+ if type(addr) == type(''):
+ f = socket.AF_UNIX
+ else:
+ f = socket.AF_INET
+
+ asynchat.async_chat.__init__ (self)
+ self.create_socket (f, socket.SOCK_STREAM)
+ self.set_terminator ('\r\n\r\n')
+ self.buffer = ''
+ self.connect (addr)
+ self.push (packet + '\r\n\r\n')
+ self.number = number
+ self.count = 0
+
+ def handle_connect (self):
+ pass
+
+ def found_terminator (self):
+ self.count = self.count + 1
+ if self.count == self.number:
+ sys.stdout.write('.'); sys.stdout.flush()
+ self.close()
+ else:
+ test_channel.found_terminator (self)
+
import time
class timer:
- def __init__ (self):
- self.start = time.time()
-
- def end (self):
- return time.time() - self.start
-
+ def __init__ (self):
+ self.start = time.time()
+
+ def end (self):
+ return time.time() - self.start
+
if __name__ == '__main__':
- import string
-
- if '--poll' in sys.argv:
- sys.argv.remove ('--poll')
- use_poll=1
- else:
- use_poll=0
-
- if len(sys.argv) == 1:
- print 'usage: %s\n' \
- ' (as a server) [--poll] -s <ip> <port>\n' \
- ' (as a client) [--poll] -c <ip> <port> <packet-size> <num-packets> <num-connections>\n' % sys.argv[0]
- sys.exit(0)
- if sys.argv[1] == '-s':
- s = test_server ((sys.argv[2], string.atoi (sys.argv[3])))
- asyncore.loop(use_poll=use_poll)
- elif sys.argv[1] == '-c':
- # create the packet
- packet = string.atoi(sys.argv[4]) * 'B'
- host = sys.argv[2]
- port = string.atoi (sys.argv[3])
- num_packets = string.atoi (sys.argv[5])
- num_conns = string.atoi (sys.argv[6])
-
- t = timer()
- for i in range (num_conns):
- test_client ((host,port), packet, num_packets)
- asyncore.loop(use_poll=use_poll)
- total_time = t.end()
-
- # ok, now do some numbers
- bytes = test_client.total_in
- num_trans = num_packets * num_conns
- total_bytes = num_trans * len(packet)
- throughput = float (total_bytes) / total_time
- trans_per_sec = num_trans / total_time
-
- sys.stderr.write ('total time: %.2f\n' % total_time)
- sys.stderr.write ( 'number of transactions: %d\n' % num_trans)
- sys.stderr.write ( 'total bytes sent: %d\n' % total_bytes)
- sys.stderr.write ( 'total throughput (bytes/sec): %.2f\n' % throughput)
- sys.stderr.write ( ' [note, throughput is this amount in each direction]\n')
- sys.stderr.write ( 'transactions/second: %.2f\n' % trans_per_sec)
-
- sys.stdout.write (
- string.join (
- map (str, (num_conns, num_packets, len(packet), throughput, trans_per_sec)),
- ','
- ) + '\n'
- )
+ import string
+
+ if '--poll' in sys.argv:
+ sys.argv.remove ('--poll')
+ use_poll=1
+ else:
+ use_poll=0
+
+ if len(sys.argv) == 1:
+ print 'usage: %s\n' \
+ ' (as a server) [--poll] -s <ip> <port>\n' \
+ ' (as a client) [--poll] -c <ip> <port> <packet-size> <num-packets> <num-connections>\n' % sys.argv[0]
+ sys.exit(0)
+ if sys.argv[1] == '-s':
+ s = test_server ((sys.argv[2], string.atoi (sys.argv[3])))
+ asyncore.loop(use_poll=use_poll)
+ elif sys.argv[1] == '-c':
+ # create the packet
+ packet = string.atoi(sys.argv[4]) * 'B'
+ host = sys.argv[2]
+ port = string.atoi (sys.argv[3])
+ num_packets = string.atoi (sys.argv[5])
+ num_conns = string.atoi (sys.argv[6])
+
+ t = timer()
+ for i in range (num_conns):
+ test_client ((host,port), packet, num_packets)
+ asyncore.loop(use_poll=use_poll)
+ total_time = t.end()
+
+ # ok, now do some numbers
+ bytes = test_client.total_in
+ num_trans = num_packets * num_conns
+ total_bytes = num_trans * len(packet)
+ throughput = float (total_bytes) / total_time
+ trans_per_sec = num_trans / total_time
+
+ sys.stderr.write ('total time: %.2f\n' % total_time)
+ sys.stderr.write ( 'number of transactions: %d\n' % num_trans)
+ sys.stderr.write ( 'total bytes sent: %d\n' % total_bytes)
+ sys.stderr.write ( 'total throughput (bytes/sec): %.2f\n' % throughput)
+ sys.stderr.write ( ' [note, throughput is this amount in each direction]\n')
+ sys.stderr.write ( 'transactions/second: %.2f\n' % trans_per_sec)
+
+ sys.stdout.write (
+ string.join (
+ map (str, (num_conns, num_packets, len(packet), throughput, trans_per_sec)),
+ ','
+ ) + '\n'
+ )
--- Updated File test_medusa.py in package Zope2 --
--- test_medusa.py 2001/04/25 19:09:55 1.2
+++ test_medusa.py 2001/05/01 11:45:27 1.3
@@ -8,44 +8,44 @@
now = http_date.build_http_date (time.time())
cache_request = string.joinfields (
- ['GET / HTTP/1.0',
- 'If-Modified-Since: %s' % now,
- ],
- '\r\n'
- ) + '\r\n\r\n'
+ ['GET / HTTP/1.0',
+ 'If-Modified-Since: %s' % now,
+ ],
+ '\r\n'
+ ) + '\r\n\r\n'
nocache_request = 'GET / HTTP/1.0\r\n\r\n'
def get (request, host='', port=80):
- s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- s.connect (host, port)
- s.send (request)
- while 1:
- d = s.recv (8192)
- if not d:
- break
- s.close()
-
+ s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
+ s.connect (host, port)
+ s.send (request)
+ while 1:
+ d = s.recv (8192)
+ if not d:
+ break
+ s.close()
+
class timer:
- def __init__ (self):
- self.start = time.time()
- def end (self):
- return time.time() - self.start
-
+ def __init__ (self):
+ self.start = time.time()
+ def end (self):
+ return time.time() - self.start
+
def test_cache (n=1000):
- t = timer()
- for i in xrange (n):
- get(cache_request)
- end = t.end()
- print 'cache: %d requests, %.2f seconds, %.2f hits/sec' % (n, end, n/end)
-
+ t = timer()
+ for i in xrange (n):
+ get(cache_request)
+ end = t.end()
+ print 'cache: %d requests, %.2f seconds, %.2f hits/sec' % (n, end, n/end)
+
def test_nocache (n=1000):
- t = timer()
- for i in xrange (n):
- get(nocache_request)
- end = t.end()
- print 'nocache: %d requests, %.2f seconds, %.2f hits/sec' % (n, end, n/end)
-
+ t = timer()
+ for i in xrange (n):
+ get(nocache_request)
+ end = t.end()
+ print 'nocache: %d requests, %.2f seconds, %.2f hits/sec' % (n, end, n/end)
+
if __name__ == '__main__':
- test_cache()
- test_nocache()
+ test_cache()
+ test_nocache()
--- Updated File test_single_11.py in package Zope2 --
--- test_single_11.py 2001/04/25 19:09:55 1.2
+++ test_single_11.py 2001/05/01 11:45:27 1.3
@@ -6,48 +6,48 @@
import socket
def build_request_chain (num, host, request_size):
- s = 'GET /test%d.html HTTP/1.1\r\nHost: %s\r\n\r\n' % (request_size, host)
- sl = [s] * (num-1)
- sl.append (
- 'GET /test%d.html HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n' % (
- request_size, host
- )
- )
- return string.join (sl, '')
-
+ s = 'GET /test%d.html HTTP/1.1\r\nHost: %s\r\n\r\n' % (request_size, host)
+ sl = [s] * (num-1)
+ sl.append (
+ 'GET /test%d.html HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n' % (
+ request_size, host
+ )
+ )
+ return string.join (sl, '')
+
import time
class timer:
- def __init__ (self):
- self.start = time.time()
-
- def end (self):
- return time.time() - self.start
-
+ def __init__ (self):
+ self.start = time.time()
+
+ def end (self):
+ return time.time() - self.start
+
if __name__ == '__main__':
- import sys
- if len(sys.argv) != 5:
- print 'usage: %s <host> <port> <request-size> <num-requests>' % (sys.argv[0])
- else:
- host = sys.argv[1]
- [port, request_size, num_requests] = map (
- string.atoi,
- sys.argv[2:]
- )
- chain = build_request_chain (num_requests, host, request_size)
- import socket
- s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- s.connect ((host,port))
- t = timer()
- s.send (chain)
- num_bytes = 0
- while 1:
- data = s.recv(16384)
- if not data:
- break
- else:
- num_bytes = num_bytes + len(data)
- total_time = t.end()
- print 'total bytes received: %d' % num_bytes
- print 'total time: %.2f sec' % (total_time)
- print 'transactions/sec: %.2f' % (num_requests/total_time)
+ import sys
+ if len(sys.argv) != 5:
+ print 'usage: %s <host> <port> <request-size> <num-requests>' % (sys.argv[0])
+ else:
+ host = sys.argv[1]
+ [port, request_size, num_requests] = map (
+ string.atoi,
+ sys.argv[2:]
+ )
+ chain = build_request_chain (num_requests, host, request_size)
+ import socket
+ s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
+ s.connect ((host,port))
+ t = timer()
+ s.send (chain)
+ num_bytes = 0
+ while 1:
+ data = s.recv(16384)
+ if not data:
+ break
+ else:
+ num_bytes = num_bytes + len(data)
+ total_time = t.end()
+ print 'total bytes received: %d' % num_bytes
+ print 'total time: %.2f sec' % (total_time)
+ print 'transactions/sec: %.2f' % (num_requests/total_time)