Am 18.07.2013 um 12:33 schrieb Sabine Knöfel <[email protected]>:
> Hi, > > Currently, I create one single Instance of Mongo when starting the Image. > > | theRoot | > theRoot := Mongo default. > theRoot open. > > and use it for all requests. In my development environment that works fine. > > My question is: is this the right way and will it work for production? No, certainly not. If you restart mongo db e.g. due a system update the connection from the image would be stale serving you errors. > Or is it better to create one Mongo instance for each request (and close it > after the request)? That is theoretically the safest thing but very expensive. Opening a connection always takes time and consume quite some resources. So reuse is king. > And, btw: what would happen if I would open many Mongo connections but never > close any? You would run out of external semaphores in the image. The image is "somewhat broken" in this regard because it cannot expand the semaphore table. As each connection uses three semaphores you are running out of semaphores after 85 requests. > Or better one Instance per user session? > That can be a good idea but it doesn't solve your actual problem. You also need to take care of concurrent requests. The line protocol to the mongo database needs to be aligned and it is binary. If more threads try to write on the same connection the connection will break. I'm not sure if this is still possible in the newest MongoTalk driver nor do I know if I managed it to release my thread safe mongo instance. The pool Mariano is talking about sounds like a good idea. Otherwise wrap your store method with an exception handler to reopen a connection on failure. Norbert
