473,395 Members | 1,658 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,395 software developers and data experts.

Network performance

Hi!

I need a fast protocol to use between a client and a server, both
sides written i Python.

What the protocol has to accomplish is extremely simple; the client
sends a number of lines (actually a RDF) and the server accepts or
rejects the packet. That's all !

Now, presently I'm using Twisted and XMLRPC ( why so is a long
history which I will not go into here) and that is a bit to slow for
my needs. On my present setup it takes close to 200 ms to perform one
transfer. But since that includes setting up and tearing down the
connection I thought I'd try doing something simpler so I wrote a
server and a client using socket.

The client sends a number of lines (each ending with \n) and ends one
set of lines with a empty line.
When the client sends a line with only a "." it means "I'm done close
the connection".

Letting the client open the connection and sending a number of sets I
was surprised to find that the performance was equal to what Twisted/
XMLRPC did. Around 200 ms per set, not significantly less.

So what can be done to speed up things or is Python incapable of
supporting fast networking (just a teaser).

-- Roland


Aug 23 '05 #1
4 6391
Roland Hedberg wrote:
What the protocol has to accomplish is extremely simple; the client
sends a number of lines (actually a RDF) and the server accepts or
rejects the packet. That's all ! .... Now, presently I'm using ( why so is a long
history which I will not go into here) and that is a bit to slow for
my needs. On my present setup [Twisted and XMLRPC ]it takes close to
200 ms to perform one transfer. But since that includes setting up and
tearing down the connection I thought I'd try doing something simpler
so I wrote a server and a client using socket. I was surprised to find that the performance was equal to what
Twisted/XMLRPC did. Around 200 ms per set, not significantly less.


That should tell you two things:
* Twisted/XMLRPC is as efficient as you can hand craft. (which is a
good use reason for using it).
* That what you're measuring is overhead - and most likely of setup.

I'd measure the ping time between your two hosts. Why? TCP is not the
fastest protocol in the world. If you're measuring the whole
connection, you're dealing with a number of TCP messages:
* Client -> SYN
* Server -> SYN ACK
* Client -> ACK
* Client -> DATA (Assume data fits inside one message)
* Server -> ACK
* Client -> FIN
* Server -> FIN ACK
* Server -> FIN
* Client -> FIN ACK
(Based on Fig 18.3, Steven TCP/IP Ill, Vol 2)

That's 9 round trips. 200ms / 9 == 22.2 ms

*IF* your ping time is close to this, then what you're really measuring
is TCP setup/teardown latency, not python latency. (*IF* you're on a
LAN and the latency is around that I'd suggest that you may have
discovered a local network problem)

If your ping time is significantly lower - eg you're running on
localhost - I'd suggest you translate your code to C (and/or post
your code), and repeat the same tests. So far you haven't shown
that python is slow here, just that something that you're measuring
causes it to be 200ms whether you use Twisted or not. (So you HAVE
shown that twisted isn't slow :-)

Another issue might be how you're measuring the latency - especially
whether if you're including startup of python in the 200ms or not!

Regards,
Michael.
--
Mi************@rd.bbc.co.uk, http://kamaelia.sourceforge.net/
British Broadcasting Corporation, Research and Development
Kingswood Warren, Surrey KT20 6NP

This message (and any attachments) may contain personal views
which are not the views of the BBC unless specifically stated.

Aug 23 '05 #2

23 aug 2005 kl. 10.14 skrev Michael Sparks:
Roland Hedberg wrote:
I was surprised to find that the performance was equal to what
Twisted/XMLRPC did. Around 200 ms per set, not significantly less.

That should tell you two things:
* Twisted/XMLRPC is as efficient as you can hand craft. (which is a
good use reason for using it).


I already gathered that much :-)
* That what you're measuring is overhead - and most likely of
setup.
Not necessarily! If the number of client - server queries/responses
are large enough the effect of the setup time should be negligible.
Or making testes with different numbers of queries you should be able
to deduce the setup time.
I'd measure the ping time between your two hosts.

If your ping time is significantly lower - eg you're running on
localhost - I'd suggest you translate your code to C (and/or post
your code),


I did the tests on localhost!

And I did post the code!

So, I made another test. I used a server I have already written in C
and which I know quite well how fast it is.

Using a python client I've written that talks to this server, it
takes 0.8 s for the python client to start, connect and send
1000 queries. A C client is a bit faster but not a lot.

This is more in the order of what I'd like to have.

Hmm, not surprising this makes me suspect my python server
implementation :-/

-- Roland
Aug 23 '05 #3
Roland Hedberg <ro************@adm.umu.se> wrote:
[ ... ]
The client sends a number of lines (each ending with \n) and ends one
set of lines with a empty line.
When the client sends a line with only a "." it means "I'm done close
the connection".

Letting the client open the connection and sending a number of sets I
was surprised to find that the performance was equal to what Twisted/
XMLRPC did. Around 200 ms per set, not significantly less.

So what can be done to speed up things or is Python incapable of
supporting fast networking (just a teaser).
That 200ms is a dead giveaway (if you've run into this issue before).
If you've got a Linux box to hand, try sticking the server on there
and see what happens.

The key to what is going on is here:
http://www.port80software.com/200ok/...01/31/317.aspx

The easy solutions are to either change:
def send( self, rdf ):
self.s.send( rdf )
self.s.send( "\n" )


to

def send( self, rdf ):
self.s.send( rdf+"\n" )

or to self.s.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 0) after
connecting self.s .

What's going on is something like this:

1. Client sends rdf

2. Server receives rdf. But it hasn't received the \n yet, so it doesn't
have a response to send yet. And because of delayed ACK, it won't send
the ACK without the DATA packet containing that response.

3. Meanwhile, the client tries to send \n, but because Nagle is on, it
would make an underful packet, and it hasn't received the ACK from the
last packet yet, so it holds on to the \n.

4. Eventually (after 200ms on Windows and, I believe, BSDs, hence OSX,
but much less on Linux) the Server gives up waiting for a DATA packet
and sends the ACK anyway.

5. Client gets this ACK and sends the \n.

6. At which point the Server has a complete line it can process, and
sends its reponse in a DATA with the ACK to the \n "piggybacked".

So the solutions are either send rdf+"\n" as a single packet in 1, and
the exchange will skip straight to 6, avoiding the 200ms delay; or
disable Nagle so 3 doesn't hold and the Client sends the \n
immediately instead of waiting for the ACK in 5.

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Aug 23 '05 #4

23 aug 2005 kl. 15.14 skrev Sion Arrowsmith:
Roland Hedberg <ro************@adm.umu.se> wrote:
The easy solutions are to either change:

def send( self, rdf ):
self.s.send( rdf )
self.s.send( "\n" )

to

def send( self, rdf ):
self.s.send( rdf+"\n" )

or to self.s.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 0) after
connecting self.s .


I had just caught this but didn't really know way yet!
What's going on is something like this:


Excellent description !

Thanks ever so much !!

-- Roland
Aug 23 '05 #5

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

Similar topics

1
by: Ryan | last post by:
I've just inherited a system and have some concerns about the speed of connections to a remote server (SQL2000). If I do a simple select statement on the table below, it takes 14 minutes to retrive...
8
by: Stephen K. Young | last post by:
If you have not seen it, this recent Microsoft Knowledge Base article is worth reading: http://support.microsoft.com/kb/889588 "How to optimize Office Access and Jet database engine...
2
by: S. van Beek | last post by:
Dear reader, By working with a frond-end and back-end databases with the use of linked tables the performance, if both mdb's are on a local drive is reasonable. But in case the backend is...
0
by: Bijesh | last post by:
Hi All, I'm using the .NET performance counters to calculate the network utilization. But this value exceeds 100%. In most of the cases, it is very similar to the one shown in the task-manager....
0
by: bimalendug | last post by:
Hi All, I'm using the .NET performance counters to calculate the network utilization. But this value exceeds 100%. In most of the cases, it is very similar to the one shown in the task-manager....
7
by: Lee | last post by:
Hi, I'm a stream virgin and am attempting to output strings to a file. My approach is to write the string initially to a 'stringstream' and only when complete write the stringstream to the file...
1
by: Scott McDaniel | last post by:
I would like to know a little bit more about how Access works over a network. My situation is: A split database with the program .mdb installed on the workstation and the backend .mdb on the...
3
by: Tony | last post by:
With respect to the questions below, please assume that our database(s) and all text files are shared on a network file server. When opening a shared MDB, what is the effect of its accessing data...
12
by: kers | last post by:
Hello, New here. Have been searching this forum for a couple of hours now ( i am not kddin).... Havnt been able to find the solution to my problem. I have a access database. Split front and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.