473,839 Members | 1,455 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 2996
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
3771
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
3021
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
2342
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
2523
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
1891
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
6615
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
7591
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
1480
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
3797
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
9855
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9697
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
10586
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...
1
10647
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10293
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...
1
7828
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
5682
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...
2
4064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3133
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.