From: Gregor H. <g.h...@gm...> - 2005-09-20 06:50:43
|
Hi, I am evaluationg using Webware instead of plain python CGI. I therefore run some benchmark tests, and discovered that there is no difference in time needed between the webware and the cgi script. I am a little bit surprised, because I thought webware must be theoretically faster, because of the cached database connection and the interpreter startup overhead with cgi. Do you have a explanantion for that? Are my benchmarks wrong, or is it just the thruth that under this circumstances cgi is as fast as webware. Python 2.2, Apache, Linux Redhat 9 (2.4.20), WebWare 0.81, Single Processor P4, 500 MB RAM Running the benchmak script, profile says for testwebware: 55254 function calls (55219 primitive calls) in 0.760 CPU seconds and testcgi: 54505 function calls in 0.800 CPU seconds Running testpsycopg says: 5356 function calls in 0.380 CPU seconds benchmark script: =========================================================================== #!/usr/bin/python import urllib as u import profile import psycopg import os def testcgi(): for i in range(100): u.urlopen("http://localhost/cgi-bin/perftestcgi.py") def testwebware(): for i in range(100): u.urlopen("http://localhost/cgi-bin/WebKit.cgi/perftest.py") def testpsycopg(): for i in range(100): c = psycopg.connect("dbname=timcos_0") os.popen2("python") c.close() profile.run("testcgi()") ===================================================================== The cgi script: --------------- #!/usr/bin/python import psycopg print "content-type: text/html" print c = psycopg.connect("dbname=timcos_0") cu = c.cursor() cu.execute("select * from donework;") r = cu.fetchall() print("<html><body>%s</html></body>" % r) c.close() =================================================================== The webware servlet: ------------------- #!/usr/bin/env python from WebKit.Page import Page import psycopg class (Page): def __init__(self, *args, **KWs): print "INIT" Page.__init__(self, *args, **KWs) self.c = psycopg.connect("dbname=timcos_0") def writeBody(self): cu = self.c.cursor() cu.execute("select * from donework;") r = cu.fetchall() self.writeln("%s" % r) -- Greg |
From: Stephan D. <ste...@gm...> - 2005-09-20 07:07:42
|
On Tuesday 20 September 2005 08:50, Gregor Horvath wrote: > Hi, > > I am evaluationg using Webware instead of plain python CGI. [...] > > def testcgi(): > for i in range(100): > u.urlopen("http://localhost/cgi-bin/perftestcgi.py") > > def testwebware(): > for i in range(100): > u.urlopen("http://localhost/cgi-bin/WebKit.cgi/perftest.py") As long as you invoke Webware with the CGI adapter, you can't see any speed= =20 improvement over plain CGI. =46rom the docs=20 (http://www.webwareforpython.org/Webware/WebKit/Docs/InstallGuide.html#pyth= on-cgi-adapter) =2D------------------------------------------------------------------------= =2D------------------------------------------ Though it's not recommended, there is an equivalent CGI script written in=20 Python. This script is substantially slower, as it requires a Python=20 interpreter to be started for each request. It is located in=20 WebKit/Adapters/WebKit.cgi -- you may wish to point the first line=20 (#!/usr/bin/env python) to the actual path of the Python interpreter (e.g.,= =20 #!/usr/local/bin/python). Otherwise, follow the instructions for wkcgi. There is no configuration, an= d=20 WebKit.cgi should be able to find the host and port of the AppServer=20 automatically. =2D------------------------------------------------------------------------= =2D---------------------------------------------- Please try mod_webware as an adapter as it is the fastest way to connect to= a=20 webware application server. Hope that helps Stephan > > def testpsycopg(): > for i in range(100): > c =3D psycopg.connect("dbname=3Dtimcos_0") > os.popen2("python") > c.close() > > profile.run("testcgi()") [...] |
From: Chuck E. <chu...@gm...> - 2005-09-20 07:54:40
|
On 9/20/05, Stephan Diehl <ste...@gm...> wrote: > On Tuesday 20 September 2005 08:50, Gregor Horvath wrote: > > Hi, > > > > I am evaluationg using Webware instead of plain python CGI. > [...] > > > > def testcgi(): > > for i in range(100): > > u.urlopen("http://localhost/cgi-bin/perftestcgi.py") > > > > def testwebware(): > > for i in range(100): > > u.urlopen("http://localhost/cgi-bin/WebKit.cgi/perftest.py") >=20 > As long as you invoke Webware with the CGI adapter, you can't see any spe= ed > improvement over plain CGI. Oh, yeah. That too. :-) Although you could still see some speedup for complex apps with many imported modules (WebKit.cgi only imports a few and the WebKit app server stays resident) and in-memory caches. -Chuck |
From: Stephan D. <ste...@gm...> - 2005-09-20 08:24:55
|
Hi Gregor, On Tuesday 20 September 2005 09:58, you wrote: > Hi, > > Stephan Diehl schrieb: > > Please try mod_webware as an adapter as it is the fastest way to connect > > to a webware application server. > > I installed the mod_webware adapater and changed > > def testwebware(): > for i in range(100): > u.urlopen("http://localhost/WK/perftest.py") > > Now, it es even slower! > > 55250 function calls (55215 primitive calls) in 1.040 CPU seconds > > ???? I'm quite sure that you've tested something, but probably not what you intended to test. First of all, Benchmarking is quite difficult. The method, you are using (profile) is good, if you want to know the number of function calls and the relative times the program spends inside them. You are basicly measuring, how urllib.urlopen behaves. The measuring overhead with profile is so heavy, that the absolute numbers have no meaning whatsoever. In order to get any meaningfull numbers, you should use some Load and Performance Test Tools that have nothing to do with Python. I've never needed to do this kind of tests, so I can't recommend any, but I'm sure that several people on this list know the right kind of tools. Stephan > > -- > Greg |
From: Robert F. <fo...@zi...> - 2005-09-20 08:31:01
|
Stephan Diehl wrote: >I've never needed to do this kind of tests, so I can't recommend any, but I'm >sure that several people on this list know the right kind of tools. > > apache bench should be the right tool for this job. http://httpd.apache.org/docs/1.3/programs/ab.html regards, robert >Stephan > > >>-- >>Greg >> >> > > >------------------------------------------------------- >SF.Net email is sponsored by: >Tame your development challenges with Apache's Geronimo App Server. Download >it for free - -and be entered to win a 42" plasma tv or your very own >Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php >_______________________________________________ >Webware-discuss mailing list >Web...@li... >https://lists.sourceforge.net/lists/listinfo/webware-discuss > >. > > > -- the idea is to keep the green alien landing craft from taking up humans from the ground and changing them into mutants. a mutant is very dangerous to you, because it flies faster than you do and shoots at you. |
From: Shayne O'N. <sh...@pe...> - 2005-09-20 07:41:33
|
Try reloading a quick acting cgi page 100 times over. Thats where the diference lies. On Tue, 20 Sep 2005, Gregor Horvath wrote: > Hi, > > I am evaluationg using Webware instead of plain python CGI. > I therefore run some benchmark tests, and discovered that there is no > difference in time needed between the webware and the cgi script. > I am a little bit surprised, because I thought webware must be theoretically > faster, because of the cached database connection and the interpreter startup > overhead with cgi. > Do you have a explanantion for that? Are my benchmarks wrong, or is it just > the thruth that under this circumstances cgi is as fast as webware. > > Python 2.2, Apache, Linux Redhat 9 (2.4.20), WebWare 0.81, Single Processor > P4, 500 MB RAM > > Running the benchmak script, profile says for testwebware: > > 55254 function calls (55219 primitive calls) in 0.760 CPU seconds > > and testcgi: > > 54505 function calls in 0.800 CPU seconds > > Running testpsycopg says: > > 5356 function calls in 0.380 CPU seconds > > benchmark script: > =========================================================================== > #!/usr/bin/python > > import urllib as u > import profile > import psycopg > import os > > > def testcgi(): > for i in range(100): > u.urlopen("http://localhost/cgi-bin/perftestcgi.py") > > def testwebware(): > for i in range(100): > u.urlopen("http://localhost/cgi-bin/WebKit.cgi/perftest.py") > > def testpsycopg(): > for i in range(100): > c = psycopg.connect("dbname=timcos_0") > os.popen2("python") > c.close() > > profile.run("testcgi()") > > ===================================================================== > The cgi script: > --------------- > > #!/usr/bin/python > > > import psycopg > > print "content-type: text/html" > print > > c = psycopg.connect("dbname=timcos_0") > cu = c.cursor() > cu.execute("select * from donework;") > r = cu.fetchall() > print("<html><body>%s</html></body>" % r) > c.close() > > =================================================================== > The webware servlet: > ------------------- > > #!/usr/bin/env python > > > from WebKit.Page import Page > import psycopg > > class (Page): > > def __init__(self, *args, **KWs): > > print "INIT" > Page.__init__(self, *args, **KWs) > self.c = psycopg.connect("dbname=timcos_0") > > > def writeBody(self): > > cu = self.c.cursor() > cu.execute("select * from donework;") > r = cu.fetchall() > self.writeln("%s" % r) > > > > -- > Greg > > > ------------------------------------------------------- > SF.Net email is sponsored by: > Tame your development challenges with Apache's Geronimo App Server. Download > it for free - -and be entered to win a 42" plasma tv or your very own > Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php > _______________________________________________ > Webware-discuss mailing list > Web...@li... > https://lists.sourceforge.net/lists/listinfo/webware-discuss > |
From: Chuck E. <chu...@gm...> - 2005-09-20 07:52:23
|
On 9/19/05, Gregor Horvath <g.h...@gm...> wrote: > Hi, >=20 > I am evaluationg using Webware instead of plain python CGI. > I therefore run some benchmark tests, and discovered that there is no > difference in time needed between the webware and the cgi script. > I am a little bit surprised, because I thought webware must be > theoretically faster, because of the cached database connection and the > interpreter startup overhead with cgi. > Do you have a explanantion for that? Are my benchmarks wrong, or is it > just the thruth that under this circumstances cgi is as fast as webware. >=20 > Python 2.2, Apache, Linux Redhat 9 (2.4.20), WebWare 0.81, Single > Processor P4, 500 MB RAM >=20 > Running the benchmak script, profile says for testwebware: >=20 > 55254 function calls (55219 primitive calls) in 0.760 CPU seconds >=20 > and testcgi: >=20 > 54505 function calls in 0.800 CPU seconds >=20 > Running testpsycopg says: >=20 > 5356 function calls in 0.380 CPU seconds I tested WebKit vs. CGI a long time ago and got a *huge* speed up due to CGI's overhead such as: - launching the Python interpreter as a new process - importing various modules (sys, time, os, cgi, etc.) I didn't measure in CPU seconds for function calls. I measured in requests per seconds. I got an even bigger speed boost when there was any configurations, database records or computed values that I could cache (and there often are). Some thoughts on your speed test: - There is very little Python code in the CGI script or servlet. My own web apps have plenty of Python code to put the page together, so if I was testing I would try something that looks more typical. - I trust the profile module to help me locate bottlenecks in my Python code, but for speed tests like this I prefer wall time: (untested) import time def durationOf(run, iterations=3D1000): # notice bigger range r =3D range(iterations) start =3D time.time() for i in r: # multiple calls to reduce overhead from "for" run() run() run() run() run() run() run() run() run() run() duration =3D time.time() - start print 'duration of %s is %s' % (run, duration) return duration def this(): ... def that(): ... durationOf(this) durationOf(that) Also, exit email, exit all web browsers and shut down as many other programs as possible before running. What kind of results do you get then? -Chuck |
From: Gregor H. <g.h...@gm...> - 2005-09-20 09:30:15
|
Hi everbody, thanks for your input. I changed the test function according to Chucks suggestion and the results are: duration of <function testcgi at 0x401986f4> is 532.231880903 duration of <function testwebware at 0x40591df4> is 127.881435156 duration of <function testwebwarewkcgi at 0x40591e2c> is 1289.3273561 I have also made some test with ab: ab -n 500 http://localhost/cgi-bin/perftestcgi.py Requests per second: 19.33 [#/sec] (mean) ab -n 500 http://localhost/cgi-bin/WebKit.cgi/perftest Requests per second: 7.54 [#/sec] (mean) ab -n 500 http://localhost/WK/perftest Requests per second: 48.12 [#/sec] (mean) Now this seems to be realistic. Seems that my test funktion was not accurate. Webware (with mod_webware) is the winner, although not dramatically. But the speed gain with webware under real conditions can only be better than those unrealistic test scripts. Interesting that WebKit.cgi is much slower than plain cgi. Thanks a lot! The new used test script: #!/usr/bin/python import urllib as u import profile #import psycopg import os import time def durationOf(run, iterations=1000): # notice bigger range r = range(iterations) start = time.time() for i in r: # multiple calls to reduce overhead from "for" run() run() run() run() run() run() run() run() run() run() duration = time.time() - start print 'duration of %s is %s' % (run, duration) return duration def testcgi(): u.urlopen("http://localhost/cgi-bin/perftestcgi.py") def testwebware(): u.urlopen("http://localhost/WK/perftest.py") def testwebwarewkcgi(): u.urlopen("http://localhost/cgi-bin/WebKit.cgi/perftest") def testpsycopg(): for i in range(100): c = psycopg.connect("dbname=timcos_0") os.popen2("python") c.close() #profile.run("testwebware()") #durationOf(testcgi) durationOf(testwebwarewkcgi) Sorry for sending some private emails, I meant to send to the list. -- Greg |
From: Christoph Z. <ci...@on...> - 2005-09-20 08:13:24
|
Gregor Horvath wrote: > Do you have a explanantion for that? Are my benchmarks wrong, or is it > just the thruth that under this circumstances cgi is as fast as webware. You seem to be using the Python CGI adapter with Webware. Under this circumstances, you will really see no difference. CGI programs are slow, because they have to (1) create and destroy a process and (2) start the Python interpreter every time they are used. The Python CGI adapter (WebKit.cgi) shares both of these disadvantages with ordinary CGI Python scripts. Webware comes with an adapter written in C (wkcgi, WebKit.exe) that eliminates problem (2) and is therefore much faster. Webware also contains an Apache adapter written in C (webkit_mod) that eliminates both problems (1) and (2). I really recommend using webkit_mod with Webware. Note that there are two different versions of the adapter, for Apache1.x and Apache2.x. See also: http://www.webwareforpython.org/Webware/WebKit/Docs/InstallGuide.html#adapters Try to make another benchmark comparing the various adapters. Concerning the benchmark, it also depends on how fast your servlet is. If the time for starting new processes is short in comparison with the time the servlet uses, then of course you will not measure the performance of the web framework, but the performance of the CGI programs themselves or the performance of the database. But even if you use the Python CGI adapeter, Webware still has many advantages over plain CGI. You can use the whole stuff the framework provides. You can cache data more easily using Webware. This will often make a big difference in performance. -- Christoph |