Created
July 18, 2011 04:31
-
-
Save j2labs/1088546 to your computer and use it in GitHub Desktop.
Concurrent pymongo inserts with Eventlet
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 | |
### | |
### Concurrent pymongo inserts | |
### | |
import eventlet | |
pymongo = eventlet.import_patched('pymongo') | |
### Setup database connection | |
dbc = pymongo.Connection() | |
db = dbc.test | |
### Prepare concurrent resources | |
pool = eventlet.GreenPool(1000) | |
def do(*args, **kwargs): | |
db.test_coll.insert(*args) | |
dbc.end_request() | |
for i in xrange(1000): | |
pool.spawn_n(do, {'num': i}) | |
pool.waitall() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What version of pymongo is imported here?