Skip to content

Instantly share code, notes, and snippets.

View j2labs's full-sized avatar

The Ghost Of J2 Labs j2labs

View GitHub Profile
@j2labs
j2labs / gist:2146589
Created March 21, 2012 12:24
Basic Python Metaclasses with Configurable Options
#!/usr/bin/env python
import inspect
import copy
###
### Options Classes
###
class DocOptions(object):
@j2labs
j2labs / gist:2027568
Created March 13, 2012 08:18
1000 concurrent downloads: gevent vs multiprocessing cc1.4xlarge
ubuntu@ip-10-17-167-43:~$ ./downloading_complete.py
With Multiprocessing:
Took 2.014980793 seconds...
ubuntu@ip-10-17-167-43:~$ ./downloading_complete.py
With Multiprocessing:
Took 6.96465492249 seconds...
ubuntu@ip-10-17-167-43:~$ ./downloading_complete.py
With Multiprocessing:
Took 5.79786896706 seconds...
ubuntu@ip-10-17-167-43:~$ ./downloading_complete.py
@j2labs
j2labs / gist:2027537
Created March 13, 2012 08:06
1000 conncurrent downloads: gevent vs. multiprocessing on c1.medium
With Gevent:
Took 4.23808407784 seconds...
ubuntu@ip-10-244-197-204:~$ ./downloading_complete.py
With Gevent:
Took 9.72512888908 seconds...
ubuntu@ip-10-244-197-204:~$ ./downloading_complete.py
With Gevent:
Took 4.29909491539 seconds...
ubuntu@ip-10-244-197-204:~$ ./downloading_complete.py
With Gevent:
@j2labs
j2labs / gist:2027506
Created March 13, 2012 07:54
1000 downloads: gevent vs multiprocessing c1.small
With Multiprocessing:
Took 37.3345718384 seconds...
ubuntu@domU-12-31-39-09-29-F2:~$ ./downloading_complete.py
With Multiprocessing:
Took 36.8940429688 seconds...
ubuntu@domU-12-31-39-09-29-F2:~$ ./downloading_complete.py
With Multiprocessing:
Took 37.2605760098 seconds...
ubuntu@domU-12-31-39-09-29-F2:~$ ./downloading_complete.py
With Multiprocessing:
@j2labs
j2labs / gist:2027421
Created March 13, 2012 07:28
1000 downloads: multiprocessing vs. gevent
jd@bean : 03:24:17 : ~/Projects/playpen/gevent
$ ./downloading_complete.py
With Multiprocessing:
Took 32.3140609264 seconds...
jd@bean : 03:26:32 : ~/Projects/playpen/gevent
$ ./downloading_complete.py
With Gevent:
Took 32.6940128803 seconds...
@j2labs
j2labs / gist:2027390
Created March 13, 2012 07:16
gevent vs. multiproessing
jd@bean : 03:11:32 : ~/Projects/playpen/gevent
$ ./downloading_complete.py
With Multiprocessing:
Took 5.50151801109 seconds...
(ks27)
jd@bean : 03:11:50 : ~/Projects/playpen/gevent
$ ./downloading_complete.py
With Multiprocessing:
Took 11.5246450901 seconds...
(ks27)
@j2labs
j2labs / core.py
Created March 4, 2012 09:17 — forked from kracekumar/core.py
parallelpip demo
#! -*- Coding: utf-8 -*-
"""
Before running the create a virtualenv (I used version 1.7, so no-site-packages is default), activate virtualenv and install gevent, envoy and try running
"""
from gevent import monkey
monkey.patch_all()
import gevent
import time
@j2labs
j2labs / gist:1839289
Created February 15, 2012 22:00
Function decorators, class decorators and sometimes arguments.
#!/usr/bin/env python
# Decorator Function
def log(f):
def _inner(*a, **kw):
print 'Calling your function'
return f(*a, **kw)
return _inner
@j2labs
j2labs / gist:1763847
Created February 8, 2012 01:05
A fresh cerealization.
$ python ./cereal.py
Dumping:
json: 16.3266839981
simplejson: 21.8916499615
cjson: 5.22964906693
ujson: 2.02208805084
cPickle: 18.5925779343
tnetstrings: 60.592509985
tnetstring: 2.44516205788
msgpack: 21.7611129284
# gevent
from gevent import monkey
monkey.patch_all()
from gevent.wsgi import WSGIServer
http_server = WSGIServer(('', port), app)
http_server.serve_forever()
# tornado
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer