473,395 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SockerServer.TCPServer problem

huy
Hi All,

Can someone explain why this bit of code can't keep up with some java
code which spawns about 200 (threads) simultaneous connections each
sending about 10 mesgs each. I basically don't get the 2000 connections
i expect on the python side. I end up with some number very close on
different runs eg. 1989, 1972, 1992 etc.

Any ideas ?

Huy

#!/usr/local/bin/python

import socket
import struct
import time
import SocketServer
import thread
from datetime import datetime

import os
import datetime
import random

LISTENING_PORT = 1600

cnt = 0

class PDAHandler(SocketServer.BaseRequestHandler):
def handle(self):
global cnt

cnt += 1
s = self.request
dlen = s.recv(4, socket.MSG_WAITALL)
print "Received: ", dlen, cnt, " from ", s.getpeername()
dataLen = struct.unpack("!i", dlen)
data = s.recv(dataLen[0])
f = file("aaa/recv%02d.txt" % cnt, "w+")
f.write(data)
f.close()
def start_servers():
msg_server = SocketServer.TCPServer(("", LISTENING_PORT), PDAHandler)
msg_server.serve_forever()

if __name__ == "__main__":
start_servers()
Jul 18 '05 #1
3 2972
huy wrote:
Hi All,

Can someone explain why this bit of code can't keep up with some java
code which spawns about 200 (threads) simultaneous connections each
sending about 10 mesgs each. I basically don't get the 2000
connections i expect on the python side. I end up with some number
very close on different runs eg. 1989, 1972, 1992 etc.
<snip>

(Sorry if I post this twice - I'm trying out a new mail client.)

You may want to try using the ThreadingTCPServer class rather than
TCPServer. Just change this line:
msg_server = SocketServer.TCPServer(("", LISTENING_PORT), PDAHandler)

to this:

msg_server = SocketServer.ThreadingTCPServer(("", LISTENING_PORT),
PDAHandler)

BTW - how are you tracking how many connections you have open with the
Python server? It may be that the process accepts the connection, puts
them into a queue to be handled, and waits for the deals with them as it
can. Or is the 2000 the total number of connections that the 200
threads produce over the whole run (each making 10 connections)?
Jeremy Jones
Jul 18 '05 #2
huy
Jeremy Jones wrote:
huy wrote:
Hi All,

Can someone explain why this bit of code can't keep up with some java
code which spawns about 200 (threads) simultaneous connections each
sending about 10 mesgs each. I basically don't get the 2000
connections i expect on the python side. I end up with some number
very close on different runs eg. 1989, 1972, 1992 etc.

<snip>

(Sorry if I post this twice - I'm trying out a new mail client.)

You may want to try using the ThreadingTCPServer class rather than
TCPServer. Just change this line:
msg_server = SocketServer.TCPServer(("", LISTENING_PORT), PDAHandler)


to this:

msg_server = SocketServer.ThreadingTCPServer(("", LISTENING_PORT),
PDAHandler)


Thanks, I'll try that.
BTW - how are you tracking how many connections you have open with the
Python server? It may be that the process accepts the connection, puts
them into a queue to be handled, and waits for the deals with them as it
can. Or is the 2000 the total number of connections that the 200
threads produce over the whole run (each making 10 connections)?

every connection creates a file. i count the number of files created.
Jeremy Jones

Jul 18 '05 #3
On Wed, 18 Aug 2004 01:28:39 +1000, huy <ny*****@swiftdsl.com.au>
declaimed the following in comp.lang.python:

every connection creates a file. i count the number of files created.
And how are the file names generated? Is there no chance that
two threads may not generate the same name and overwrite each other?

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
0
by: lee | last post by:
I have a TCP/IP client and server I have written in c# using sockets and asynchronous methods. I am having a problem with the server if a client is closed without explicitly disconnecting from the...
1
by: dcrespo | last post by:
Hi all, Below, you can see a class that when it receives a host connection, it gets validated. Then, if the validation returns True, then process the request. Also, if I want to stop the server,...
6
by: Ant | last post by:
Hi all, I'm putting together a simple help module for my applications, using html files stored in the application directory somewhere. Basically it sets up a basic web server, and then uses the...
0
by: danishce | last post by:
Hello All: I am developing a client/server application using vb.net winsock programming. I am sending data to Server and at the same time receive the incoming data from the server. My application...
2
by: Eric Spaulding | last post by:
Is there an easy way to pass arguments to a handler class that is used by the standard TCPServer? normally --srvr =SocketServer.TCPServer(('',port_num), TCPHandlerClass) I'd like to be able...
6
by: Larry Bates | last post by:
Every time I look at the logging module (up until now) I've given up and continue to use my home-grown logger that I've been using for years. I'm not giving up this time ;-) I find that I...
3
by: Daniel | last post by:
Hello, I can't seem to get my sockets code to work right. Here is what I have inside my RequestHandler handle() function: total_data= data = True...
1
by: =?Utf-8?B?RGFydGgtQ3ot?= | last post by:
Hi, I'm beginner in Visual C++ so I want to ask you a question. And I'm not good in English:D So I have the program which communicates over sockets. The program has to connect to the server and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.