Created
January 28, 2010 08:58
-
-
Save saivenkat/288562 to your computer and use it in GitHub Desktop.
Eventlet based url timer
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
import time | |
from eventlet import coros | |
from eventlet.green import urllib2 | |
def fetch(url): | |
print "%s fetching %s" % (time.asctime(), url) | |
data = urllib2.urlopen(url) | |
print "%s fetched %s" % (time.asctime(), data.read()) | |
def load(url, pool_size): | |
pool = coros.CoroutinePool(max_size=pool_size) | |
waiters = [] | |
start = time.time() | |
for i in range(1, pool_size): | |
waiters.append(pool.execute(fetch, url)) | |
for waiter in waiters: | |
waiter.wait() | |
end = time.time() | |
print "Time taken for %s requests is %.8f seconds" %(pool_size, end - start) | |
if __name__ == '__main__': | |
load("http://localhost:9999", 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment