0

I have python web app (WSGi) which is deployed using uwsgi and nginx. I am going to provide this app to many users (customers) - each user will have his own settgins, database, templates, data folder etc. The code of the app can be shared.

My original idea was to have one uwsgi process per customer. But it is quite wasteful approach, because currently the app has about 100MB memory footprint. I expect that most of these instances will be sleeping most of the time (max 500 requests per day).

I came up with this solution:

The app will be modified in the way, that one instance may serve for more customers. Based on the requested domain, it will prepare (load) the right settings, database connection etc. for that customer.

Is this good idea? Or should I rather focus on lowering the memory footprint?

Thank you for your answers!

2
  • What if multiple users are requesting the same domain? Commented May 1, 2013 at 12:16
  • I hope that I did not simplify the question too much... but of course, the app is (and will be) run multiple times (multiprocess) and is threaded. Commented May 1, 2013 at 12:20

1 Answer 1

1

The app will be modified in that way, that one instance may serve for more customers. Based on requested domain, it will prepare (load) the right settings, database connection etc. for that customer.

Is this good idea?

Well, I've used a similar system in production whereby there are n instances of the app, but each instance can serve any customer, based on the HTTP Host header, and it works quite well.

Given a sufficiently large number of customers, it may not be cost-effective, or even practical, to have one instance per customer.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you very much fo response. Have you faced any unexpected issues with this system? At the first sight, it seems quite straightforward to implement to me.
@JoshuaBoshi Not really, although the system was designed to work that way from the ground up, rather than being modified later on. It was mostly to make it trivial to add new customers later on, and also makes it easier to handle domain redirections. I can't really be more specific without seeing some example code from your implementation. For example, if context switching is expensive, e.g. the loading of settings, and making DB connections you mention, then you might have issues. All I can suggest is to try it out, and see how well it works.
Right, I should have asked about this sooner :) But I think, it will not be such a problem. I will use sqlalchemy´s connection pooling and keep other stuff (like settings) in memory (for each customer), so the context switch cost should be minimal. Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.