用SocketServer.ThreadingTCPServer建的socket服务,能同时支持多少并发数

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

用SocketServer.ThreadingTCPServer建的socket服务,能同时支持多少并发数

韩志刚-2
正在学习python编程
用SocketServer.ThreadingTCPServer建了socket服务端.然后写了个客户端起1000
个线程去访问这个server
def test():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('192.168.0.65', SERVER_PORT))
sock.sendall('1234567890')
recvData = sock.recv(MAX_PACKET_SIZE)
print 'Recv from server', recvData
sock.close()

if __name__ == '__main__':
for i in range(1000):
thread.start_new_thread(test)
time.sleep(0.1)

如果我在服务端的handle(self)中加入很小的延时函数,客户端就报连接拒绝
"socket.error: (111, 'Connection refused')"
我猜想是服务端的并发不够了,怎么才能增加server端的并发数??

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 用SocketServer.ThreadingTCPServer建的socket服务,能同时支持多少并发数

pt42
 同问

在 08-1-24,hanzg<[hidden email]> 写道:

> 正在学习python编程
> 用SocketServer.ThreadingTCPServer建了socket服务端.然后写了个客户端起1000
> 个线程去访问这个server
> def test():
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> sock.connect(('192.168.0.65', SERVER_PORT))
> sock.sendall('1234567890')
> recvData = sock.recv(MAX_PACKET_SIZE)
> print 'Recv from server', recvData
> sock.close()
>
> if __name__ == '__main__':
> for i in range(1000):
> thread.start_new_thread(test)
> time.sleep(0.1)
>
> 如果我在服务端的handle(self)中加入很小的延时函数,客户端就报连接拒绝
> "socket.error: (111, 'Connection refused')"
> 我猜想是服务端的并发不够了,怎么才能增加server端的并发数??
>
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 用SocketServer.ThreadingTCPServer建的socket服务,能同时支持多少并发数

wen lu
In reply to this post by 韩志刚-2
hanzg 写道:
> 正在学习python编程 用SocketServer.ThreadingTCPServer建了socket服务端.然后写了个客户端起
> 1000 个线程去访问这个server def test(): sock = socket.socket(socket.AF_INET,
> socket.SOCK_STREAM) sock.connect(('192.168.0.65', SERVER_PORT))
> sock.sendall('1234567890') recvData = sock.recv(MAX_PACKET_SIZE)
> print 'Recv from server', recvData sock.close()
>
> if __name__ == '__main__': for i in range(1000):
> thread.start_new_thread(test) time.sleep(0.1)
>
> 如果我在服务端的handle(self)中加入很小的延时函数,客户端就报连接拒绝 "socket.error: (111,
> 'Connection refused')" 我猜想是服务端的并发不够了,怎么才能增加server端的并发数??
>
> _______________________________________________ python-chinese Post:
> send [hidden email] Subscribe: send subscribe to
> [hidden email] Unsubscribe: send unsubscribe
> to  [hidden email] Detail Info:
> http://python.cn/mailman/listinfo/python-chinese


hanzg 写道:
正在学习python编程
用SocketServer.ThreadingTCPServer建了socket服务端.然后写了个客户端起1000
个线程去访问这个server
def test():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('192.168.0.65', SERVER_PORT))
sock.sendall('1234567890')
recvData = sock.recv(MAX_PACKET_SIZE)
print 'Recv from server', recvData
sock.close()

if __name__ == '__main__':
for i in range(1000):
thread.start_new_thread(test)
time.sleep(0.1)

如果我在服务端的handle(self)中加入很小的延时函数,客户端就报连接拒绝
"socket.error: (111, 'Connection refused')"
我猜想是服务端的并发不够了,怎么才能增加server端的并发数??

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
reuseaddress选项的问题?


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 用SocketServer.ThreadingTCPServer建的socket服务,能同时支持多少并发数

kilnt huo
In reply to this post by 韩志刚-2
线程数与os本身有关,linux 很多版本默认只有 255 。可用253。

> 如果我在服务端的handle(self)中加入很小的延时函数,客户端就报连接拒绝
> "socket.error: (111, 'Connection refused')"
> 我猜想是服务端的并发不够了,怎么才能增加server端的并发数??
>
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese