Python's paster serve app.ini
is taking longer than I would like to be ready for the first request.
I know how to profile requests with middleware, but how do I profile the initialization time? I would like it to not fork a thread pool and quit as soon as it is ready to serve so the time after it's ready doesn't show up in the profile.
I almost always use
paster serve --reload ...
during development. That command executes itself as a subprocess (it executes its own script using thesubprocess
module, notfork()
).The subprocess polls for source code changes, quits when it detects a change, and gets restarted by the parent
paster serve --reload
.That's to say if you're going to profile
paster serve
itself, omit the--reload
argument. Profiling individual requests with middleware should work fine either way.My particular problem was that
pkg_resources
takes an amount of time proportional to all installed packages when it is first invoked. I solved it by rebuilding my virtualenv without unnecessary packages.