Most of the time I'm not doing bulk inserts / updates though. It's an update or two on this request, an insert on that one, and a half dozen new records during a background task. The second solution doesn't work here.
The first solution (multiple threads) will prevent throughput problems, but it means that thread is going to block and screw up my response times. The application shouldn't have to wait 70-100ms for each database write it makes.
What about deferring save operations with something like Celery? I'd hate to pass data through more potential methods of failure, but maybe writing out my own write ahead log would work.
@task(ignore_result=True)
def write_save (col, op, *args, **kwargs):
write_ahead.delay(col, *args, **kwargs)
getattr(col, op)(j=True, *args, **kwargs)
Here's a second question, if I write something (either with j=True or without) does it get cached on the client before it receives the response from the server?
For example:
collection.save({"name" : "josh"})
collection.find({"name" : "josh"}) # Does this find the object I just sent down for saving?