473,756 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

performance problem of streaming data over TCP

Hi, friends,

I am implementing a protocol on top of 'asyncore.dispa tcher' to
send streaming multimedia data over TCP socket. However, I found that
the throughput of my current implementation is surprisingly low.

Below is a snippet of my code with a note that: the packet sent
over the socket is of variable length, of which the first a couple bytes
indicates the length of the packet. I implemented a 'var_str_to_int '
function to get the 'length' and the offset of the payload.

############### ############### ############### ##
def handle_read(sel f):
self.socket.set blocking(1)
while (True) :
data =
self.assemble_m sg()
if (not data) :
self.socket.set blocking(0)
return
(length,index) = var_str_to_int( data)
self._dispatch_ cmd(data[index:])
if (not self.recv_buffe r) :
break
self.socket.set blocking(0)

def assemble_msg(se lf) :
if (self.recv_buff er) :
data = self.recv_buffe r
else :
data = self.socket.rec v(self.BUFFER_S IZE)
if (len(data) == 0) :
return None
length,index = var_str_to_int( data)
while (length +index > len(data)) :
data += self.socket.rec v(self.BUFFER_S IZE)
if (length + index == len(data)) :
self.recv_buffe r = ''
else :
self.recv_buffe r = data[length+index:]
data = data[:length+index]
return data
############### ############### ############### ##

I found it took around 7 seconds to receive a packet of 40KB sent
from localhost. The throughput is even not enough to support any
streaming multimedia file for live playback in a LAN.

I read some threads in the group. It sounds like the problem might
have to do with the TCP option, setting TCP_NODELAY probably could solve
the problem. But I tried the following on both a Linux and a windows XP
machine. Neither of them worked:

############### ############### ############### #
self.socket.set sockopt(socket. IPPROTO_TCP, socket.TCP_NODE LAY, 1)
############### ############### ############### #

Any comments or suggests is highly appreciated.

Thanks,
Changhao
May 20 '06 #1
2 1990
I figured out the reason. It was because of asyncore.dispat cher's
inefficient implementation of messange sending. Instead of using its
'push' method. I directly call the underlying 'socket.send' and got the
problem solved. Sorry about the spam.

Thanks

Changhao wrote:
Hi, friends,

I am implementing a protocol on top of 'asyncore.dispa tcher' to send
streaming multimedia data over TCP socket. However, I found that the
throughput of my current implementation is surprisingly low.

Below is a snippet of my code with a note that: the packet sent over
the socket is of variable length, of which the first a couple bytes
indicates the length of the packet. I implemented a 'var_str_to_int '
function to get the 'length' and the offset of the payload.

############### ############### ############### ##
def handle_read(sel f):
self.socket.set blocking(1)
while (True) :
data =
self.assemble_m sg()
if (not data) :
self.socket.set blocking(0)
return
(length,index) = var_str_to_int( data)
self._dispatch_ cmd(data[index:])
if (not self.recv_buffe r) :
break
self.socket.set blocking(0)

def assemble_msg(se lf) :
if (self.recv_buff er) :
data = self.recv_buffe r
else :
data = self.socket.rec v(self.BUFFER_S IZE)
if (len(data) == 0) :
return None
length,index = var_str_to_int( data)
while (length +index > len(data)) :
data += self.socket.rec v(self.BUFFER_S IZE)
if (length + index == len(data)) :
self.recv_buffe r = ''
else :
self.recv_buffe r = data[length+index:]
data = data[:length+index]
return data
############### ############### ############### ##

I found it took around 7 seconds to receive a packet of 40KB sent
from localhost. The throughput is even not enough to support any
streaming multimedia file for live playback in a LAN.

I read some threads in the group. It sounds like the problem might
have to do with the TCP option, setting TCP_NODELAY probably could solve
the problem. But I tried the following on both a Linux and a windows XP
machine. Neither of them worked:

############### ############### ############### #
self.socket.set sockopt(socket. IPPROTO_TCP, socket.TCP_NODE LAY, 1)
############### ############### ############### #

Any comments or suggests is highly appreciated.

Thanks,
Changhao

May 20 '06 #2
Changhao wrote:
I am implementing a protocol on top of 'asyncore.dispa tcher' to
send streaming multimedia data over TCP socket. However, I found that
the throughput of my current implementation is surprisingly low.


I'm not sure what you think you're doing in your code, but I'm quite
sure that using a home-brewed blocking loop inside an event handler in a
high-performance asynchronous framework isn't exactly the best way to
get good performance. Have you tried using asyncore for asynchronous
communication ?

</F>

May 20 '06 #3

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

Similar topics

1
1455
by: WildHare | last post by:
What exactly is streaming? When I use a browser or an application and it gets streaming data (say, Headlines, Stock Quotes, etc), what is it really doing. Is it just that the client is constantly making new requests for information from a given web server, or is there more magic to it? It sounds like we are opening a connection and getting a constant "stream" of information...is this the case, or is it just an illusion. If it really...
22
5697
by: googlegroups | last post by:
I am playing with the XMLHTTPRequest method to perform client/server transactions. I have it set up right now so that when readyState is 4, it takes the XML and processes it. This works great until there is alot of data. In that case, the user will have to wait for the data to come back which may take a minute or so. I don't want the user to have to wait. Is it possible for javascript to periodically (while still receiving more data)...
25
1914
by: Daniel P. | last post by:
MS or anyone still claims that C# and VB.NET generate the exact same IL code? http://www.osnews.com/story.php?news_id=5602&page=3
5
1569
by: John | last post by:
Hi all, I have an (well, what I think to be, at least) interesting question: Is it possible to stream data down to the client and, after a certain amount of data has been streamed, allow the client to begin interacting with that data whilst still streaming data down? Also, if it is possible, how would one go about coding this? Would some sort of predfined bit of streaming be finished and notify the client (i.e. some form of Javascript...
5
1609
by: Tom Gurath | last post by:
http://osnews.com/story.php?news_id=5602&page=2 This benchmark tests the Math & File I/O of 9 languages/run-times. Visual C++ (Version 7 - not managed) Visual C# gcc C Visual Basic.NET Visual J# Java 1.3.1 Java 1.4.2
2
9753
by: mpaliath | last post by:
Hi guys I am currently involved in a project which requires me to recieve and play streaming video as well as send it. In Visual C++ is there any free library which helps me do this as 'streaming' is not part of the actual project, i am allowed to use external libraries. Also could anyone tell me where I can learn about video streaming in c++ so I can code the streaming part myself too thx
3
4700
by: Vijay | last post by:
Hi Folks, I having one issue, in my application I am going to use the server push for streaming the data by keeping the connection open. At client side, i am having the XMhttprequest object (i.e ActiveX object of IE). When the data comes, onreadystatechange method get callback on state 3 but it doesn't allow me to read the data from the object. It says 'The data necessary to complete this operation is not yet available'. Is it...
9
2190
by: starlight | last post by:
Hallo, there were some posts about this, but nothing I could find useful. I have a large XML file (80MB) and need certain information out of it. I though I could use XSLT with an fairy simple transformation: .... <xsl:for-each select="/values/STRING/item"> <tr class="own"> <td><xsl:value-of select="A"/></td> <td><xsl:value-of select="B"/></td>
5
3552
by: pmakoi | last post by:
dear all this might be a piece of cake for some of you out there but it is causing me a lot of stress given the fact that there is not enogh documentation out there regarding this topic I am writing a web service that uses soap with attachments to send a large streaming data, The concept works quite well but when I started to test it I got this problem. When my client program calls a method that should return a real time data the...
0
9431
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
9844
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
9819
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
9689
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
8688
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
7226
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
6514
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
5119
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...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.