Python HTTP SSL服务器接受连接速度慢

以下python代码用于创buildHTTPS服务器。

''' Created on 23/07/2014 @author: o880732 ''' import sys import BaseHTTPServer import base64 from multiprocessing import Process, Queue from httplib import HTTPSConnection import ssl import datetime class MyHttpEndpointHandler(BaseHTTPServer.BaseHTTPRequestHandler): def __init__(self, q, *args): self.q = q BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args) def do_POST(self): self.send_response(200, 'OK') self.send_header('Server', 'Apache-Coyote/1.1') self.send_header('Content-type','text/xml') self.end_headers() # Extract and print the contents of the POST length = int(self.headers['Content-Length']) print "Length of content is " + str(length) post_data = self.rfile.read(length) self.q.put(post_data) class ServerEndpointHandler: def __init__(self,q,keyfile,certfile): self.q = q self.keyfile = keyfile self.certfile = certfile def setupEndpointHandler(self, queue): return lambda *args: MyHttpEndpointHandler(queue, *args) def handleEndpoint(self): print "Starting endpoint handler" handler = self.setupEndpointHandler(self.q) httpd = BaseHTTPServer.HTTPServer(('',8443), handler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=self.keyfile, certfile = self.certfile, server_side=True) httpd.serve_forever() if __name__ == '__main__': q = Queue() print "trying to start endpoint" ep = ServerEndpointHandler(q, keyfile="~/certificates/server.key", certfile = "~/certificates/server.crt") t2 = Process(target=ep.handleEndpoint) t2.start() t2.join() 

我的问题是,在RedhatLinux服务器上接受连接的时间大约是20秒,而在Windows7下运行的相同代码的连接时间大约是200毫秒。

这两个系统都运行Python 2.6.6。

redhat发行版是6.4(圣地亚哥)

 Linux myserver.domain.com 2.6.32-358.18.1.el6.x86_64 #1 SMP Fri Aug 2 17:04:38 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux 

我已经将openssl和python包更新到Redhat的当前版本。

 Installed Packages openssl.x86_64 1.0.1e-16.el6_5.14 @rhel-x86_64-server-6 python.x86_64 2.6.6-52.el6 @rhel-x86_64-server-6 Available Packages openssl.i686 1.0.1e-16.el6_5.14 rhel-x86_64-server-6 python.i686 2.6.5-3.el6_0.2 rhel-x86_64-server-6 

我假设这个延迟与协议谈判有关,我想知道在哪里寻求解决这个问题,或者是什么问题。

任何线索?

这听起来像DNS失败。 你可以尝试添加这样的东西到MyHttpEndpointHandler

 def address_string(self): """ Override address_string() with a version that skips the reverse lookup. """ return '%s:%s' % self.client_address