var sys = require ( 'sys' ) , http = require ( 'http' ) ; http. createServer ( function ( req , res ) { setTimeout ( function ( ) { res. sendHeader ( 200 , { 'Content-Type' : 'text/plain' } ) ; res. sendBody ( 'Hello World' ) ; res. finish ( ) ; } , 2000 ) ; } ) . listen ( 8000 ) ; sys. puts ( 'Server running at 127.0.0.1:8000/' ) ;
var sys = require ( 'sys' ) , http = require ( 'http' ) ; http. createServer ( function ( req , res ) { setTimeout ( function ( ) { res. sendHeader ( 200 , { 'Content-Type' : 'text/plain' } ) ; res. sendBody ( 'Hello World' ) ; res. finish ( ) ; } , 2000 ) ; } ) . listen ( 8000 ) ; sys. puts ( 'Server running at 127.0.0.1:8000/' ) ;
var sys = require ( 'sys' ) , http = require ( 'http' ) ; http. createServer ( function ( req , res ) { setTimeout ( function ( ) { res. sendHeader ( 200 , { 'Content-Type' : 'text/plain' } ) ; res. sendBody ( 'Hello World' ) ; res. finish ( ) ; } , 2000 ) ; } ) . listen ( 8000 ) ; sys. puts ( 'Server running at 127.0.0.1:8000/' ) ;
var sys = require ( 'sys' ) , http = require ( 'http' ) ; http. createServer ( function ( req , res ) { setTimeout ( function ( ) { res. sendHeader ( 200 , { 'Content-Type' : 'text/plain' } ) ; res. sendBody ( 'Hello World' ) ; res. finish ( ) ; } , 2000 ) ; } ) . listen ( 8000 ) ; sys. puts ( 'Server running at 127.0.0.1:8000/' ) ;
var sys = require ( 'sys' ) , http = require ( 'http' ) ; http. createServer ( function ( req , res ) { setTimeout ( function ( ) { res. sendHeader ( 200 , { 'Content-Type' : 'text/plain' } ) ; res. sendBody ( 'Hello World' ) ; res. finish ( ) ; } , 2000 ) ; } ) . listen ( 8000 ) ; sys. puts ( 'Server running at 127.0.0.1:8000/' ) ;
var sys = require ( 'sys' ) , http = require ( 'http' ) ; http. createServer ( function ( req , res ) { setTimeout ( function ( ) { res. sendHeader ( 200 , { 'Content-Type' : 'text/plain' } ) ; res. sendBody ( 'Hello World' ) ; res. finish ( ) ; } , 2000 ) ; } ) . listen ( 8000 ) ; sys. puts ( 'Server running at 127.0.0.1:8000/' ) ;
var sys = require ( 'sys' ) , http = require ( 'http' ) ; http. createServer ( function ( req , res ) { setTimeout ( function ( ) { res. sendHeader ( 200 , { 'Content-Type' : 'text/plain' } ) ; res. sendBody ( 'Hello World' ) ; res. finish ( ) ; } , 2000 ) ; } ) . listen ( 8000 ) ; sys. puts ( 'Server running at 127.0.0.1:8000/' ) ;
var sys = require ( 'sys' ) , http = require ( 'http' ) ; http. createServer ( function ( req , res ) { setTimeout ( function ( ) { res. sendHeader ( 200 , { 'Content-Type' : 'text/plain' } ) ; res. sendBody ( 'Hello World' ) ; res. finish ( ) ; } , 2000 ) ; } ) . listen ( 8000 ) ; sys. puts ( 'Server running at 127.0.0.1:8000/' ) ;
var sys = require ( 'sys' ) , http = require ( 'http' ) ; http. createServer ( function ( req , res ) { setTimeout ( function ( ) { res. sendHeader ( 200 , { 'Content-Type' : 'text/plain' } ) ; res. sendBody ( 'Hello World' ) ; res. finish ( ) ; } , 2000 ) ; } ) . listen ( 8000 ) ; sys. puts ( 'Server running at 127.0.0.1:8000/' ) ;
var sys = require ( 'sys' ) , http = require ( 'http' ) ; http. createServer ( function ( req , res ) { setTimeout ( function ( ) { res. sendHeader ( 200 , { 'Content-Type' : 'text/plain' } ) ; res. sendBody ( 'Hello World' ) ; res. finish ( ) ; } , 2000 ) ; } ) . listen ( 8000 ) ; sys. puts ( 'Server running at 127.0.0.1:8000/' ) ;
var sys = require ( 'sys' ) , http = require ( 'http' ) ; http. createServer ( function ( req , res ) { setTimeout ( function ( ) { res. sendHeader ( 200 , { 'Content-Type' : 'text/plain' } ) ; res. sendBody ( 'Hello World' ) ; res. finish ( ) ; } , 2000 ) ; } ) . listen ( 8000 ) ; sys. puts ( 'Server running at 127.0.0.1:8000/' ) ;
Copy Source | Copy HTML
- #! / usr / bin / env python
- import tornado.httpserver
- import tornado.ioloop
- import tornado.web
- import time
- class MainHandler (tornado.web.RequestHandler):
- def get (self):
- time .sleep (2)
- self. write ("Hello World")
- application = tornado.web.Application ([
- (r "/", MainHandler),
- ])
- if __name__ == "__main__":
- http_server = tornado.httpserver.HTTPServer (application)
- http_server.listen (8888)
- tornado.ioloop.IOLoop.instance (). start ()
ab -n 10 -c 10 http://127.0.0.1:8888/ Time taken for tests: 20.078 seconds
ab -n 10 -c 10 http://127.0.0.1:8000/ Time taken for tests: 2.007 seconds
I didn’t want to offend Python, because the whole thing is that time.sleep is a blocking function, that is, it blocks the entire event loop, just as the event loop in python is blocked by almost everything related to input and output, and only advanced programmers know how to do it. or another action without blocking the interpreter, and often davolno solutions for this rather cumbersome and ugly.
Source: https://habr.com/ru/post/83865/