SEE:Karigell~最易用的Web应用框架!

Karrigell 多线程增强

ccnusjy <ccnusjy@gmail.com>
reply-to        karrigell@googlegroups.com
to      karrigell <karrigell@googlegroups.com>
date    Sat, Aug 23, 2008 at 18:14

PyProcessing 本质增强

   1 import os
   2 import traceback
   3 import sys
   4 
   5 import KarrigellRequestHandler
   6 import k_config, k_utils
   7 import webservers.SimpleAsyncHTTPServer as Server
   8 from processing import Process, currentProcess, freezeSupport
   9 if sys.platform == 'win32':
  10    import processing.reduction    # make sockets pickable/inheritable
  11 
  12 class
  13 asyncRequestHandler(KarrigellRequestHandler.KarrigellRequestHandler,
  14        Server.DialogManager):
  15 
  16    def handle_data(self):
  17 
  18 KarrigellRequestHandler.KarrigellRequestHandler.handle_data(self)
  19 
  20    def send_error(self, code, message=None):
  21 
  22 KarrigellRequestHandler.KarrigellRequestHandler.send_error(self,
  23            code,message)
  24 
  25    def handle_error(self):
  26        traceback.print_exc(file=sys.stderr)
  27 
  28 def kkk_serve(s):
  29    #print k_config.silent
  30    #if k_config.silent:
  31    sys.stdout = k_utils.silent()
  32    sys.stderr = k_utils.silent()
  33    try:
  34        s.loop()
  35    except KeyboardInterrupt:
  36        s.close_all()
  37        k_utils.trace("Ctrl+C pressed. Shutting down.")
  38 
  39 def main_start():
  40    # Launch the server
  41    port = 8086
  42    process_num = 3
  43 
  44    s = Server.Server(('localhost',port),asyncRequestHandler)
  45 
  46    print "Karrigell %s running on port %s" %
  47 (KarrigellRequestHandler.__version__,
  48        port)
  49    print "Press Ctrl+C to stop"
  50 
  51    for i in range(process_num):
  52        child = Process(target=kkk_serve, args=(s,))
  53        child.setDaemon(True)
  54        child.start()
  55 
  56    kkk_serve(s)
  57 
  58 if __name__ == '__main__':
  59    if sys.platform == 'win32':
  60        freezeSupport()
  61    main_start()

增强使用说明

Hi, you can put the script above to a file called
Karrgiell_multiprocess.py , and then double click it to run Karrigell
Server with many process instances which are all running at the same
tcp port.

As we all know, Karrigell handle custom's request one by one, so one a
long-running script is executing, other request seams to be blocked .

Now, there is no problem about that with the power of pyprocessing


> def main_start():
>     # Launch the server
>     port = 8086
#~~~~~~~~~~~~~~ ,here is the port your server will listen to
>     process_num = 3
#~~~~~~~~~~~~~~, here is how many process instances to serve
>
>     s = Server.Server(('localhost',port),asyncRequestHandler)

特别修订

modification of a Karrigell's file "core/k_config.py".:

in line 44:

try:
   _opts, _args = getopt.getopt(sys.argv[1:], "hP:L:SR",['processing-
fork'])

#~~~~~~~~~~~~~ here
   print _opts,_args
except getopt.GetoptError:
   # print usage information and exit:
   usage()
   raise

forked lost the arguments of their parent process, and they had their own arguments in sys.argv ('processing-fork' and a process id).

idea, tell me please.

同类选择

ccnusjy <ccnusjy@gmail.com>
reply-to        karrigell@googlegroups.com
to      karrigell <karrigell@googlegroups.com>
date    Sun, Aug 24, 2008 at 22:08

Graham Dumpleton <Graham.Dumpleton@gmail.com>
reply-to        karrigell@googlegroups.com
to      karrigell <karrigell@googlegroups.com>
date    Sun, Aug 24, 2008 at 14:07
subject [karrigell] Re: Karrigell + PyProcessing,Very good and Strong!

You are aware you can get multiprocess Karrigell by using mod_wsgi?

压力测试

junyi sun <ccnusjy@gmail.com>
reply-to        karrigell@googlegroups.com
to      karrigell@googlegroups.com
date    Sat, Aug 30, 2008 at 23:49
subject [karrigell] Benchmark Report

Benchmark Report Wonderful, Karrigell's performance improved very much with the enhancement of PyProcessing!

See the data below, please.


my test code

C:\Documents and Settings\sunjoy>ab -n1000 -c100 http://localhost:8086/sjy/hello.py
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

1.Default Karrigell.py

(Only one process instance)

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests


Server Software: Karrigell/2.4.0
Server Hostname: localhost
Server Port: 8081

Document Path: /sjy/hello.py
Document Length: 12 bytes

Concurrency Level: 100
Time taken for tests: 62.359375 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 171000 bytes
HTML transferred: 12000 bytes
Requests per second: 16.04 [#/sec] (mean)
Time per request: 6235.938 [ms] (mean)
Time per request: 62.359 [ms] (mean, across all concurrent requests)
Transfer rate: 2.66 [Kbytes/sec] received

Connection Times (ms)
  min mean[+/-sd] median max
Connect: 0 61 157.2 0 515
Processing: 15 6038 2832.7 8046 8562
Waiting: 0 3213 2410.3 2515 8062
Total: 15 6099 2857.1 8046 8562

Percentage of the requests served within a certain time (ms)
  50% 8046
  66% 8046
  75% 8046
  80% 8046
  90% 8546
  95% 8546
  98% 8562
  99% 8562
 100% 8562 (longest request)

2.Karrigell with PyProcessing

(3 process instances)

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests


Server Software: Karrigell/2.4.0
Server Hostname: localhost
Server Port: 8086

Document Path: /sjy/hello.py
Document Length: 12 bytes

Concurrency Level: 100
Time taken for tests: 34.31250 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 171000 bytes
HTML transferred: 12000 bytes
Requests per second: 29.38 [#/sec] (mean)
Time per request: 3403.125 [ms] (mean)
Time per request: 34.031 [ms] (mean, across all concurrent requests)
Transfer rate: 4.88 [Kbytes/sec] received

Connection Times (ms)
  min mean[+/-sd] median max
Connect: 0 30 96.9 15 531
Processing: 15 3295 1784.6 2141 6844
Waiting: 0 1607 1427.4 1218 6375
Total: 500 3326 1800.2 2171 7015

Percentage of the requests served within a certain time (ms)
  50% 2171
  66% 3171
  75% 5515
  80% 5937
  90% 6375
  95% 6531
  98% 6546
  99% 6640
 100% 7015 (longest request)

3.Karrigell with PyProcessing

(10 process instances)

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests


Server Software: Karrigell/2.4.0
Server Hostname: localhost
Server Port: 8086

Document Path: /sjy/hello.py
Document Length: 12 bytes

Concurrency Level: 100
Time taken for tests: 19.937500 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 171000 bytes
HTML transferred: 12000 bytes
Requests per second: 50.16 [#/sec] (mean)
Time per request: 1993.750 [ms] (mean)
Time per request: 19.938 [ms] (mean, across all concurrent requests)
Transfer rate: 8.33 [Kbytes/sec] received

Connection Times (ms)
  min mean[+/-sd] median max
Connect: 0 15 24.8 0 531
Processing: 15 1952 550.1 2093 2609
Waiting: 0 1001 685.3 921 2468
Total: 15 1968 549.9 2109 2640

Percentage of the requests served within a certain time (ms)
  50% 2109
  66% 2218
  75% 2312
  80% 2390
  90% 2484
  95% 2500
  98% 2515
  99% 2515
 100% 2640 (longest request)


反馈

创建 by -- ZoomQuiet [2008-08-24 12:14:17]

KarrigellWithPyProcessingVeryGoodStrong (last edited 2009-12-25 07:11:09 by localhost)