librelist archives

« back to archive

WSGI performance

WSGI performance

From:
Braddock
Date:
2013-07-16 @ 00:01
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Is the line 'from flask import Flask, request' expensive?

The time to execute this single import statement is between 1 to 5
seconds on an ARM Fedora-18 install using mod_wsgi.

See http://pastebin.com/EA6ZZDLb for details

How do I optimize this?  Is it normally so slow?
Should I be configuring WSGI differently?

Thanks,
Braddock Gaskill
internet-in-a-box.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJR5I0/AAoJEHWLR/DQzlZu9lsH/3k8QUoBBMdb5iFTCDyfGkc/
dnPxLR8/2zPw+5zYh0hvGtFpcgRTrqcErBnT7kcJVLwSXr2YHGsulpKldAUUQDYN
ep6J3TjQkO7Bjva59815KncFHPbdNxAdHPJB9oS+L1HEPLeH6etML4Oqo9ngPmaw
4FtRaN5HoAGjDIP1rv+hL/i3euMS5u0clIiF1tinlKqIcjOgbHnRJp/+E4RzGBZj
pP9yn5/JrdABtez7xyZZmc2NYbxxE96tSphKOq4A5hhpda/zgvaU0m1bgsvfde28
bxygWgCzHG6bEJY1t8OF0sNe3CMwq1JQZKI1eiL+mYaHNGoGU+Jhg5ILfty0NFE=
=XghO
-----END PGP SIGNATURE-----

Re: [flask] WSGI performance

From:
Matthew Frazier
Date:
2013-07-16 @ 02:30
On 07/15/2013 08:01 PM, Braddock wrote:
> Is the line 'from flask import Flask, request' expensive?
>
> The time to execute this single import statement is between 1 to 5
> seconds on an ARM Fedora-18 install using mod_wsgi.
>
> See http://pastebin.com/EA6ZZDLb for details
>
> How do I optimize this?  Is it normally so slow?
> Should I be configuring WSGI differently?

In a working WSGI application, that line should only execute once for 
every time you reboot the server. Your problem is that since you're not 
defining an application file, mod_wsgi assumes there was an error 
starting up, so it's destroying and rebuilding the Python environment on 
every request.

I recommend adding a simple "Hello, world!" app to the WSGI file, then 
benchmarking. Right now, you're benchmarking a misconfigured system.
-- 
Thanks,
Matthew Frazier
http://leafstorm.us

Re: [flask] WSGI performance

From:
Braddock
Date:
2013-07-16 @ 17:35
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks Matthew.  Obviously that was a contrived example to demonstrate
the performance issue.

My problem is that the first time the user goes to the web app, the
load time is long as Flask is set up.  I was surprised to see so much
time spent just in the 'import Flask' when I profiled it.

If it is normal for Flask to take a couple seconds to import on low
powered hardware, I'll just have to live with it, or get a WSGI
process started pre-emptively.

- -braddock

On 07/15/2013 07:30 PM, Matthew Frazier wrote:
> On 07/15/2013 08:01 PM, Braddock wrote:
>> Is the line 'from flask import Flask, request' expensive?
>> 
>> The time to execute this single import statement is between 1 to
>> 5 seconds on an ARM Fedora-18 install using mod_wsgi.
>> 
>> See http://pastebin.com/EA6ZZDLb for details
>> 
>> How do I optimize this?  Is it normally so slow? Should I be
>> configuring WSGI differently?
> 
> In a working WSGI application, that line should only execute once
> for every time you reboot the server. Your problem is that since
> you're not defining an application file, mod_wsgi assumes there was
> an error starting up, so it's destroying and rebuilding the Python
> environment on every request.
> 
> I recommend adding a simple "Hello, world!" app to the WSGI file,
> then benchmarking. Right now, you're benchmarking a misconfigured
> system.
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJR5YRcAAoJEHWLR/DQzlZu3DkH/R1L/r8pfTkdvHv6aNkD/5KX
LaVyRPKzFEUxZa/wPYMrnxUxaL9JgkteLgaxPUyPgZ63MzMWoBDicqfcoEKjSE4N
l6By3yKZs+tvTdrNAXN1XzLzj9efzbF0ki5zycHO/cqKQB2Y7N1+EPrzU9VIpfSi
xGGjB+i2YMPelpyuuj09wdlz3Ju+Ol5OZMltDQspj/4zB/SuUWxNRBF+g03VsIsw
zIWKt+QX6vhZZVyhcHKDfS44dl3H7La5aijKPz3bQwkHGt8viMkEfdRkKCUt6nwL
sGgmU8FYvujGR4o3ngBxBlkkCZJTAbFcJC8FXraX0C3opvVcIm6m1H6FbgmDheY=
=LxZE
-----END PGP SIGNATURE-----