473,406 Members | 2,956 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,406 software developers and data experts.

performance problem of streaming data over TCP

Hi, friends,

I am implementing a protocol on top of 'asyncore.dispatcher' 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(self):
self.socket.setblocking(1)
while (True) :
data =
self.assemble_msg()
if (not data) :
self.socket.setblocking(0)
return
(length,index) = var_str_to_int(data)
self._dispatch_cmd(data[index:])
if (not self.recv_buffer) :
break
self.socket.setblocking(0)

def assemble_msg(self) :
if (self.recv_buffer) :
data = self.recv_buffer
else :
data = self.socket.recv(self.BUFFER_SIZE)
if (len(data) == 0) :
return None
length,index = var_str_to_int(data)
while (length +index > len(data)) :
data += self.socket.recv(self.BUFFER_SIZE)
if (length + index == len(data)) :
self.recv_buffer = ''
else :
self.recv_buffer = 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.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
##############################################

Any comments or suggests is highly appreciated.

Thanks,
Changhao
May 20 '06 #1
2 1964
I figured out the reason. It was because of asyncore.dispatcher'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.dispatcher' 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(self):
self.socket.setblocking(1)
while (True) :
data =
self.assemble_msg()
if (not data) :
self.socket.setblocking(0)
return
(length,index) = var_str_to_int(data)
self._dispatch_cmd(data[index:])
if (not self.recv_buffer) :
break
self.socket.setblocking(0)

def assemble_msg(self) :
if (self.recv_buffer) :
data = self.recv_buffer
else :
data = self.socket.recv(self.BUFFER_SIZE)
if (len(data) == 0) :
return None
length,index = var_str_to_int(data)
while (length +index > len(data)) :
data += self.socket.recv(self.BUFFER_SIZE)
if (length + index == len(data)) :
self.recv_buffer = ''
else :
self.recv_buffer = 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.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 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.dispatcher' 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
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...
22
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...
25
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
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...
5
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...
2
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...
3
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...
9
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...

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.