Skip to content

Instantly share code, notes, and snippets.

@andymccurdy
Created May 7, 2010 22:18
Show Gist options
  • Save andymccurdy/394068 to your computer and use it in GitHub Desktop.
Save andymccurdy/394068 to your computer and use it in GitHub Desktop.
import time
import threading
import redis
def worker():
print "starting thread..."
r = redis.Redis(db=9)
for i in xrange(2000):
r.incr('foo')
def worker_with_pipeline():
print "starting thread..."
r = redis.Redis(db=9)
p = r.pipeline()
for i in xrange(2000):
p.incr('foo')
p.execute()
def test(pipeline):
target = pipeline and worker_with_pipeline or worker
threads = []
for i in range(50):
threads.append(threading.Thread(target=target))
start = time.time()
for t in threads:
t.start()
for t in threads:
t.join()
end = time.time()-start
print end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment