문제

After fighting with different things here and there, I was finally able to get BottlePY running on Apache and run a MongoDB powered site. I am used to running Django apps, so I will be relating to that a bit in my question.

The Problem

Every time a page is loaded via BottlePY, the connection to the MongoDB database located on MongoHQ.com needs to be re-authenticated (meaning it probably had to reconnect).

What I Found

I attached a db.keep_alive() function to the top of each model function, so that before any mongodb query is run, it trys to run a simple query. If it fails, it catches the OperationFailure or AutoReconnect errors and then calls the db.authenticate() function. After it reauthenticates, I have it add a log to a logs db to monitor how often it needs to reauthenticate. Currently, it needs to reauthenticate on every page load (that requires running a query). This isn't right.

Difference from Django

I use this same concept in django, and have found that the db connection only needs to be authenticated after 10-15 minutes of no queries being run.

I don't understand why creating a pymongo connection in django would be different from creating one in bottle, since I am using the same driver, functions and methods. I am not using any ORMS or anything like that either.

Versions

  • Bottle: 0.9.dev
  • Django: 1.2.1 final
  • PyMongo: 1.8

I appreciate the help!

Update: A friend was able to take a quick look and noticed the following that may help with answering my question.

It appears that each request is launching a new Python process, as opposed to Django, in which a single process remains running for a long period of time.

도움이 되었습니까?

해결책

This just ended up to be a weird thing between Bottle and MongoHQ. No real solution was found, but I couldn't recreate it with other frameworks. Any other ideas are appreciated.

다른 팁

does your apache xxx.conf contain something like:

WSGIDaemonProcess project user=mysite group=www-data processes=5 threads=1 WSGIProcessGroup project

I think most important should be threads=1

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top