474,042 Members | 64,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SockerServer.TC PServer 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(Sock etServer.BaseRe questHandler):
def handle(self):
global cnt

cnt += 1
s = self.request
dlen = s.recv(4, socket.MSG_WAIT ALL)
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.TC PServer(("", LISTENING_PORT) , PDAHandler)
msg_server.serv e_forever()

if __name__ == "__main__":
start_servers()
Jul 18 '05 #1
3 3004
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 ThreadingTCPSer ver class rather than
TCPServer. Just change this line:
msg_server = SocketServer.TC PServer(("", LISTENING_PORT) , PDAHandler)

to this:

msg_server = SocketServer.Th readingTCPServe r(("", 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 ThreadingTCPSer ver class rather than
TCPServer. Just change this line:
msg_server = SocketServer.TC PServer(("", LISTENING_PORT) , PDAHandler)


to this:

msg_server = SocketServer.Th readingTCPServe r(("", 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*****@swiftd sl.com.au>
declaimed the following in comp.lang.pytho n:

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.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.ne tcom.com/> <

Jul 18 '05 #4

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

Similar topics

11
3795
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 (ClassB* b; b->func(); ) the base-class function is called instead of the new function in the derived class. All other similar functions (virtual in the base class and overwritten in the the derived class) work fine, it's just this one function. ...
0
3033
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 server, I had previously fixed this in VS 2003 by detecting a 0 byte message in the server asynchronous receive method and then cleaning up and closing the connection. However I have recently moved to VS 2005 and when the exception happens I...
1
2349
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, I simply access the self.QuitFlag in lock mode, and set it to 1. Now that you know what I have, I would like to add SRP functionality to the validation of each new connection. What I need to add to my code to get SRP to work? I don't know...
6
2533
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 webbrowser module to display it in the users browser. I have it set up to call sys.exit(0) if the url quit.html is called, but for some reason (on Windows XP via the cmd.exe shell) python won't let me have the console back. I get the System Exit...
0
1914
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 have 3 Windows Forms. 1-FrmInquiry 2-FrmSale 3-FrmBalance When i send and receive data from FrmInquiry to server it works fine but My problem is when i go to any other form(ex FrmSale) from FrmInquiry and send data from it to server, it gives...
2
6640
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 to: srvr =SocketServer.TCPServer(('',port_num), TCPHandlerClass, (arg1,arg2)) And have arg1, arg2 available via TCPHandlerClass.__init__ or some other way.
6
7602
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 REALLY need to be able to monitor LOTS of running programs/processes and thought it would be nice to have them use SocketHandler logging and then I would write TCPServer to accept the log messages for real-time monitoring. I Googled (is that now a...
3
1494
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 logger_server.debug(self.__class__.__name__ + ' set data = True')
1
3810
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 send and receive data. But when I start the program, there is one Socketexception - something like the program is unable to connect to the server or the server didn't answer... I apologize for my English... Thank you for advice...
0
10337
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11601
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
11138
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8690
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6648
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
5406
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4939
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.