473,799 Members | 2,868 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Problem with writing fast UDP server

On Fri, 21 Nov 2008 00:20:49 -0200, Gabriel Genellina <ga*******@yaho o.com.arwrote:
>En Thu, 20 Nov 2008 14:24:20 -0200, Krzysztof Retel
<Kr*********** **@googlemail.c omescribió:
>>On Nov 20, 4:00Â*pm, bieff...@gmail. com wrote:
>>>On 20 Nov, 16:03, Krzysztof Retel <Krzysztof.Re.. .@googlemail.co m>
wrote:

I am struggling writing fast UDP server. It has to handle around 10000
UDP packets per second. I started building that with non blocking
socket and threads. Unfortunately my approach does not work at all.
I wrote a simple case test: client and server. The client sends 2200
packets within 0.137447118759 secs. The tcpdump received 2189 packets,
which is not bad at all.
But the server only handles 700 -- 870 packets, when it is non-
blocking, and only 670 – 700 received with blocking sockets.
The client and the server are working within the same local network
and tcpdump shows pretty correct amount of packets received.

I wonder if there is a kind of setting for socket to allow no delays?

I've used this script to test sending UDP packets. I've not seen any
delays.

<code>
[snip]
</code>

Start the server before the client.
If you want to try this program out on POSIX, make sure you change the
time.clock() calls to time.time() calls instead, otherwise the results
aren't very meaningful.

I gave this a try on an AMD64 3200+ running a 32 bit Linux installation.
Here's the results I got on the server:

Packet count 91426
Total bytes 8228340 bytes
Total time 8.4 secs
Avg size / packet 90 bytes
Max size / packet 90 bytes
Max time / packet 41070.9 us
Min time / packet 79.9 us
Avg time / packet 92.3 us
Max speed 1100.4 Kbytes/sec
Min speed 2.1 Kbytes/sec
Avg speed 952.0 Kbytes/sec

And on the client:

Packet count 91426
Total bytes 8228340 bytes
Total time 8.4 secs
Avg size / packet 90 bytes
Max size / packet 90 bytes
Max time / packet 40936.0 us
Min time / packet 78.9 us
Avg time / packet 92.3 us
Max speed 1113.7 Kbytes/sec
Min speed 2.1 Kbytes/sec
Avg speed 952.1 Kbytes/sec

Both processes ran on the same machine and communicated over localhost.

For comparison, I tried running the client against a Twisted-based UDP
server. Here are the results from that server:

Packet count 91426
Total bytes 8228340 bytes
Total time 11.8 secs
Avg size / packet 90 bytes
Max size / packet 90 bytes
Max time / packet 55393.9 us
Min time / packet 8.8 us
Avg time / packet 128.7 us
Max speed 9963.2 Kbytes/sec
Min speed 1.6 Kbytes/sec
Avg speed 682.7 Kbytes/sec

This seemed a bit low to me though, so I tried writing an alternate client
and re-ran the measurement. Here are the new server results:

Packet count 91426
Total bytes 8228340 bytes
Total time 2.9 secs
Avg size / packet 90 bytes
Max size / packet 90 bytes
Max time / packet 38193.0 us
Min time / packet 8.8 us
Avg time / packet 32.2 us
Max speed 9963.2 Kbytes/sec
Min speed 2.3 Kbytes/sec
Avg speed 2726.7 Kbytes/sec

And then tried the new client against the original server, with these
results:

Packet count 91426
Total bytes 8228340 bytes
Total time 3.8 secs
Avg size / packet 90 bytes
Max size / packet 90 bytes
Max time / packet 23675.0 us
Min time / packet 6.9 us
Avg time / packet 41.7 us
Max speed 12711.7 Kbytes/sec
Min speed 3.7 Kbytes/sec
Avg speed 2109.0 Kbytes/sec

So it does seem that handling 10k datagrams per second should be no
problem, assuming comparable hardware, at least if whatever work you
have to do to process each one doesn't take more than about 24 25ths
of a millisecond (leaving you the remaining 1 part out of 25 of every
millisecond to receive a packet).

For reference, here's the Twisted UDP client code:

from twisted.interne t.protocol import DatagramProtoco l
from twisted.interne t import reactor
from twisted.interne t.task import LoopingCall

msg = 'xyxabc123' * 10

class EchoClientDatag ramProtocol(Dat agramProtocol):

def startProtocol(s elf):
self.transport. connect('127.0. 0.1', 8000)
LoopingCall(sel f.sendDatagrams ).start(0.00005 )

def sendDatagrams(s elf):
for i in xrange(50):
self.transport. write(msg)

def main():
protocol = EchoClientDatag ramProtocol()
t = reactor.listenU DP(0, protocol)
reactor.run()

if __name__ == '__main__':
main()

And here's the Twisted UDP server code:

from time import time as clock

from twisted.interne t.protocol import DatagramProtoco l
from twisted.interne t import reactor

class EchoUDP(Datagra mProtocol):
history = []
t0 = clock()
def datagramReceive d(self, datagram, address):
t1 = clock()
self.history.ap pend((len(datag ram), t1 - self.t0))
self.t0 = t1
if len(self.histor y) == 91427:
self.history.po p(0)
show_stats(self .history)
self.history = []

def main():
reactor.listenU DP(8000, EchoUDP())
reactor.run()

def show_stats(hist ory):
npackets = len(history)
bytes_total = sum([item[0] for item in history])
bytes_avg = float(bytes_tot al) / npackets
bytes_max = max([item[0] for item in history])
time_total = sum([item[1] for item in history])
time_max = max([item[1] for item in history])
time_min = min([item[1] for item in history])
time_avg = float(time_tota l) / npackets
speed_max = max([item[0]/item[1] for item in history if item[1]>0])
speed_min = min([item[0]/item[1] for item in history if item[1]>0])
speed_avg = float(bytes_tot al) / time_total
print "Packet count %8d" % npackets
print "Total bytes %8d bytes" % bytes_total
print "Total time %8.1f secs" % time_total
print "Avg size / packet %8d bytes" % bytes_avg
print "Max size / packet %8d bytes" % bytes_max
print "Max time / packet %8.1f us" % (time_max*1e6)
print "Min time / packet %8.1f us" % (time_min*1e6)
print "Avg time / packet %8.1f us" % (time_avg*1e6)
print "Max speed %8.1f Kbytes/sec" % (speed_max/1024)
print "Min speed %8.1f Kbytes/sec" % (speed_min/1024)
print "Avg speed %8.1f Kbytes/sec" % (speed_avg/1024)
print

if __name__ == '__main__':
main()

Nov 21 '08 #1
1 5187
On Nov 21, 3:52*am, Jean-Paul Calderone <exar...@divmod .comwrote:
>
Start the server before the client.

If you want to try this program out on POSIX, make sure you change the
time.clock() calls to time.time() calls instead, otherwise the results
aren't very meaningful.

I gave this a try on an AMD64 3200+ running a 32 bit Linux installation.
Here's the results I got on the server:
Jean-Paul, thanks very much for the code snippets.
I have tried this out with number of tests. Both approaches are
working fine when I run them on the same machine.
When I run the client (twisted version) on another machine and the udp
server (non twisted) on server machine, I got some strange behaviour.
The client send 255 messages and than it cause an error: socket.error:
(11, 'Resource temporarily unavailable')

Any idea what could be wrong?

Nov 21 '08 #2

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

Similar topics

37
10452
by: Ubaidullah Nubar | last post by:
Hi, How well is Python suited for developing database based applications? I am new to Python so please bear with me if some of the questions are too simple. I specifically have the following questions: 1. Is there an example of a simple data-entry application written in Python using a GUI interface? Something like a simple address book app with a listbox displaying all addresses with the ability to add/modify/delete.
3
1799
by: Ben Taylor | last post by:
Hi I am trying to build, more for a learning project than anything, an ASP.NET web application in C# that will run on my local machine, which has now successully got IIS installed on it (XP pro). In the first instance, I initially want it to be able to get data from MSDE via ADO.NET, and display it, hopefully in the form of a graph. Can it do this? I am mainly experienced in VB6 and a little bit of C++, but I've not really done much with...
9
5948
by: Chibi | last post by:
I'm writing an application that's bandwidth intense. My available bandwidth is 1.5Mbps (cable modem) and I know I can reach around 1.4Mbps, if not more. The application I am writing right now simply connects to a newsgroup and downloads the headers. It doesn't do any more specific programmming after that. However, the app will use, at most, 100kbps bandwidth. I'm hoping that it can run much faster than that and reach somewhere close...
29
3682
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form id="Form1" method="post" runat="server"> <%
3
500
by: Froggy / Froggy Corp. | last post by:
First thx for your quick answer :) iostat dont return bad load average. I never grow up to 1Mb/s and the IDE drive can go faster. I really can't change the server, its a locative server which i own (only me on the server, no cooperative, but i dont have physically access to it). So the configuration is ... not the best :). And at this time, i dont have money for server-hosting.
35
25154
by: rbt | last post by:
I've been doing some file system benchmarking. In the process, I need to create a large file to copy around to various drives. I'm creating the file like this: fd = file('large_file.bin', 'wb') for x in xrange(409600000): fd.write('0') fd.close() This takes a few minutes to do. How can I speed up the process?
4
4544
by: eselk | last post by:
I've never really setup or used MS SQL Server (just a couple hours, one day, several months ago). I think MS SQL Server has the ability to use "linked tables", like MS Access does. Is this correct? What I want to do is have an MS SQL Server setup, which compatible applications can talk with, but I want the data to come from a Paradox database. I can use any MS SQL version, whatever would work best. I'm not sure about the Paradox...
6
12162
by: Abandoned | last post by:
Hi.. I use the threading module for the fast operation. But i have some problems.. This is my code sample: ================= conn = psycopg2.connect(user='postgres',password='postgres',database='postgres') cursor = conn.cursor() class paralel(Thread): def __init__ (self, veriler, sayii):
11
12473
by: Krzysztof Retel | last post by:
Hi guys, I am struggling writing fast UDP server. It has to handle around 10000 UDP packets per second. I started building that with non blocking socket and threads. Unfortunately my approach does not work at all. I wrote a simple case test: client and server. The client sends 2200 packets within 0.137447118759 secs. The tcpdump received 2189 packets, which is not bad at all. But the server only handles 700 -- 870 packets, when it is...
0
10269
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
10248
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
10032
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
9085
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...
0
6811
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
5469
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
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
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.