uWSGI lazy-apps opinion

1,337 views
Skip to first unread message

Srikanth Bemineni

unread,
Dec 20, 2015, 9:32:39 PM12/20/15
to pylons-discuss

Hi ,

I am working on getting the requirements for starting a new project ,using pyramid framework. My project needs to work with both a SQL database(Mostly probably MYSql) and Cassandra. I am currently at a stage where I am deciding on the Cassandra connection issues. One of the issue that came across is the same connection used in multiple fork issue, where multiple forks of uWSGI using the same cassandra connection from the main scope and timing out. The solution is to use @post_fork() decorator,

So, My question is , what is the best practice ? is it good to enable lazy-apps, which is by default or disable lazy-apps. Will this also affect SQAlchemy DB sessions ?. What are the cons and pros of the enabling and disabling lazy-apps from pyramid perspective. Will forking  effect any other services, that we use for a basic website, like payment system, email services etc...

Srikanth Bemineni


Jason

unread,
Jan 12, 2016, 1:12:29 PM1/12/16
to pylons-discuss
I use lazy-apps in production which acts the same as an application loaded by itself. The only issue I've run into is getting uWSGI to quit if one of the lazy-app instances fails to load. There was some configuration necessary to make uWSGI exit when that happens so that supervisor could detect and report it. This may not be necessary in your case anyway. The only reason we use lazy-apps is because we didn't want to add the post_fork logic our applications at the time we setup uWSGI.

It's unlikely that forking would cause any issues except with SQLAlchemy's session pool which requires the post_fork solution. I think it is libpq that restricts it from sharing the connections with forked processes. No issues should come up with any python libraries unless they specifically say they do not support forking.

My understanding is the only difference is the amount of memory usage. When forked some of the python process memory is shared reducing the total usage. There are some graceful reloading setups that need to take into consideration lazy-apps vs forking which you can read about at http://uwsgi-docs.readthedocs.org/en/latest/articles/TheArtOfGracefulReloading.html#preforking-vs-lazy-apps-vs-lazy
 
-- Jason
Reply all
Reply to author
Forward
0 new messages