1

I'm creating an app in several different python web frameworks to see which has the better balance of being comfortable for me to program in and performance. Is there a way of reporting the memory usage of a particular app that is being run in virtualenv?

If not, how can I find the average, maximum and minimum memory usage of my web framework apps?

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
  • Do you need a detailed report of all the various memory allocations, etc..or just to know how much is being consumed by the app? – jdi Aug 10 '12 at 01:56
  • just how much is being consumed by the app within the virtualenv. –  Aug 10 '12 at 10:54

3 Answers3

1

It depends on how you're going to run the application in your environment. There are many different ways to run Python web apps. Recently popular methods seem to be Gunicorn and uWSGI. So you'd be best off running the application as you would in your environment and you could simply use a process monitor to see how much memory and CPU is being used by the process running your applicaiton.

Matt W
  • 6,078
  • 3
  • 32
  • 40
1

I'll second Matt W's note about the application environment being a major factor ( Gunicorn , uWSGI, nginx->paster/pserve, eventlet, apache+mod_wsgi, etc etc etc)

I'll also add this- the year is 2012. In 1999, memory and CPU for stuff like this were huge concerns. But it's 2012. Computers are significantly more powerful, expanding them is much easier and cheaper, and frameworks are coded better.

You're essentially looking at benchmarking things that have no practical matter and will only be theoretically 'neat' and informative.

The performance bottlenecks on Python webapps are usually:

  • database communications bottleneck
  • database schema
  • concurrent connections / requests-per-second

In terms of database communications bottleneck , the general approaches to solving it are:

  • communicate less
    • aggressive caching
    • optimize your sql queries and result sets , so there's less data
  • upgrade your db infrastructure
    • dedicated machine(s)
    • cluster master/slave or shard

In terms of database schema, convenience comes at a price. It's faster to get certain things done in Django -- but you're going to be largely stuck with the schema it creates. Pyramid+SqlAlchemy is more flexible and you can build against a finely tuned database with it... but you're not going to get any of the automagic tools that Django gives.

for concurrent connections / requests per second, it's largely due to the environment. running the same app under paster, uwsgi and other deployment strategies will have different results.

here's a link to a good , but old, benchmark - http://nichol.as/benchmark-of-python-web-servers

you'll note there's a slide for peak memory usage there, and although there are a few outliers and a decent amount of clustering going on, the worst performer had 122MB. that's nothing.

you could interpret gevent as awesome for having 3MB compared to uwsgi's 15 or cogen's 122... but these are all a small fraction of a modern system's memory.

the frameworks have such a small overhead and will barely be a factor in operating performance. even the database portions are nothing. reference this posting about SqlAlchemy ( Why is SQLAlchemy insert with sqlite 25 times slower than using sqlite3 directly? ) , where the maintainer notes some impressive performance notes: straight-up sql generation was ~.5s for 100k rows. when a full ORM with integrity checks/etc is involved , it becomes 16s for the same amount of rows. that is nothing.

So , my point is simple- the two factors you should consider are:

  • how fast / comfortable can i program now
  • how fast / comfortable can i program in a year from now ( i.e. how likely is my project to grow 'technical debt' using this framework , and how much of a problem will that become )

play with the frameworks to decide which one you like the most, but don't waste your time on performance testing , because all you're going to do is waste time.

Community
  • 1
  • 1
Jonathan Vanasco
  • 15,111
  • 10
  • 48
  • 72
  • Yes, it may be 2012 but hosting still has relatively low memory provision. Since I made the post above I set up a Plone instance on Webfaction and got warning emails about high memory usage with 512mb on a shared account. That's a fairly hefty amount of ram for something that wasn't even running five pages of content. In contrast, I have managed to write a fairly complex web app in Bottle (my current testbed) which is using 12.8mb on average with ~14000 views in an 9 hour work period and had no time to optimise it yet. As you say though, just the security aspect has taken two weeks to program. –  Sep 01 '12 at 01:30
  • From webfaction.com's pricing -- +$7/month per 256MB , which is a bit cheaper than linode.com's $10/month per 256. In either case, that's nothing. Plone isn't a framework, it's a CMS with huge overhead built on the Zope framework. Drupal in PHP is similarly bloated. You'll get good-enough performance from Bottle, Web.Py, Pyramid, Django, Tornado, Twisted, etc. – Jonathan Vanasco Sep 03 '12 at 05:03
  • Webfaction's memory allowance is limited to 512mb currently. Can't believe after all this time I've never come across Linode... good stuff. I know Plone is a CMS but it operates very well getting large amounts of data into customised content management with added ease of use for end users. This has been my issue in that I have developed a number of in-house information systems but never had to worry for ram. My upcoming project is for a foundation in Ecuador with limited funds but the audience is global. Linode might be within reach but Webfaction don't offer VPS as far as I can see either. –  Sep 03 '12 at 11:34
  • linode has been around for a while, but I never heard of them either until rackspace bought Slicehost... and Linode started getting their old audience. for a non-profit in latin america, i would consider a PHP solution for long-term maintenance. WHile I don't like PHP, there's a lot more talent that can maintain PHP there than python. – Jonathan Vanasco Sep 03 '12 at 16:53
0

The choice of hosting mechanism isn't the cause of memory usage, it is how you configure them, plus what fat Python web application you decide to run.

The benchmark being quoted of:

http://nichol.as/benchmark-of-python-web-servers

is a good example of where benchmarks can get it quite wrong.

The configurations of the different hosting mechanisms in that benchmark were not comparable and so there is no way you can use the results to evaluate memory usage of each properly. I would not pay much attention to that benchmark if memory is your concern.

Ignoring memory, some of the other comments made about where the real bottlenecks are going to be are valid. For a lot more detail on this whole issue see my PyCon talk.

http://lanyrd.com/2012/pycon/spcdg/

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134