Created
March 16, 2012 12:59
-
-
Save fiorix/2049984 to your computer and use it in GitHub Desktop.
compare txredisapi's inet vs unix sockets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
# | |
# Compare txredisapi's inet vs unix sockets. | |
# Don't forget to enable redis' unix socket prior to executing this. | |
import time | |
import txredisapi as redis | |
from twisted.internet import defer | |
from twisted.internet import reactor | |
@defer.inlineCallbacks | |
def test_set(db, n_op): | |
for n in xrange(n_op): | |
yield db.set("_t%d" % n, 1) | |
@defer.inlineCallbacks | |
def test_get(db, n_op): | |
for n in xrange(n_op): | |
yield db.get("_t%d" % n) | |
@defer.inlineCallbacks | |
def main(): | |
n_op = 50000 | |
t = time.time() | |
db = yield redis.Connection() | |
yield test_set(db, n_op) | |
#yield test_get(db, n_op) | |
inet_t = time.time() - t | |
print("INET: %d operations in %0.4fs (%d op/s)" % (n_op, inet_t, | |
n_op / inet_t)) | |
yield db.disconnect() | |
t = time.time() | |
db = yield redis.UnixConnection() | |
yield test_set(db, n_op) | |
#yield test_get(db, n_op) | |
unix_t = time.time() - t | |
print("UNIX: %d operations in %0.4fs (%d op/s)" % (n_op, unix_t, | |
n_op / unix_t)) | |
yield db.disconnect() | |
if inet_t < unix_t: | |
print("INET is %0.2f%% faster." % (100 - (inet_t * 100 / unix_t))) | |
else: | |
print("UNIX is %0.2f%% faster." % (100 - (unix_t * 100 / inet_t))) | |
reactor.stop() | |
if __name__ == "__main__": | |
main() | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment