Skip to content

Instantly share code, notes, and snippets.

@yashh
Created July 14, 2011 04:54
Show Gist options
  • Save yashh/1081962 to your computer and use it in GitHub Desktop.
Save yashh/1081962 to your computer and use it in GitHub Desktop.
pymysql load test
# stolen from tarek ziade's bug report
# https://bug667846.bugzilla.mozilla.org/attachment.cgi?id=542440
import pymysql
import time
import threading
from wsgiref.simple_server import make_server
# set up the greenlet
#from gevent import monkey
#monkey.patch_socket()
QUERY = """\
insert into wbo
(username, collection,id,parentid,predecessorid,
sortindex,modified,payload,payload_size,ttl)
values
%s
on duplicate key update
parentid = values(parentid),
predecessorid = values(predecessorid),
sortindex = values(sortindex),
modified = values(modified),
payload = values(payload),
payload_size = values(payload_size),
ttl = values(ttl)
"""
PAYLOAD = '*' * 500
LINE = """
(1, 'history', '%(id)s', -1, -1, 0, %(modified)s, '%(payload)s',
500, %(ttl)s)
"""
def sql_call():
conn = pymysql.connect(host='127.0.0.1', port=3306,
user='sync', passwd='sync', db='sync')
cur = conn.cursor()
lines = []
data = {'payload': PAYLOAD, 'modified': time.time(),
'ttl': time.time() + 1000}
lines = []
for i in range(500):
data['id'] = 'sometab%d' % time.time()
lines.append(LINE % data)
query = QUERY % ','.join(lines)
cur.execute(query)
cur.close()
conn.close()
def simple_app(environ, start_response):
status = '200 OK'
headers = [('Content-type', 'text/plain')]
start_response(status, headers)
sql_call()
ret = ['inserted\n']
print "inserted"
return ret
if __name__ == '__main__':
httpd = make_server('', 8888, simple_app)
print "Serving on port 8888..."
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment