473,659 Members | 3,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scatter/gather on sockets?

I've got a bunch of strings in a list:

vector = []
vector.append ("foo")
vector.append ("bar")
vector.append ("baz")

I want to send all of them out a socket in a single send() call, so
they end up in a single packet (assuming the MTU is large enough). I
can do:

mySocket.send ("".join (vector))

but that involves creating an intermediate string. Is there a more
efficient way, that doesn't involve that extra data copy?
Apr 1 '06 #1
5 1405
On Sat, 01 Apr 2006 14:56:02 -0500, Roy Smith wrote:
I've got a bunch of strings in a list:

vector = []
vector.append ("foo")
vector.append ("bar")
vector.append ("baz")

I want to send all of them out a socket in a single send() call, so
they end up in a single packet (assuming the MTU is large enough). I
can do:

mySocket.send ("".join (vector))

but that involves creating an intermediate string. Is there a more
efficient way, that doesn't involve that extra data copy?


Is sendall() what you're looking for?

--
A wise man knows he knows nothing.

Apr 1 '06 #2
Roy Smith wrote:
I've got a bunch of strings in a list:

vector = []
vector.append ("foo")
vector.append ("bar")
vector.append ("baz")

I want to send all of them out a socket in a single send() call, so
they end up in a single packet (assuming the MTU is large enough). I
can do:

mySocket.send ("".join (vector))

but that involves creating an intermediate string. Is there a more
efficient way, that doesn't involve that extra data copy?


Two possible answers that I can see:

A. No, the send call is implemented in C and requires a single buffer
with the entire piece of data that will be sent. Ultimately this gets
passed down to the NIC hardware in some fashion, so there's certainly no
hope of using something like a generator to send it in pieces.

B. Don't bother trying, because even if the MTU is large enough there is
absolutely no guarantee that the packet will stay intact all the way
through the network anyway (even if you use sendall() instead of send()).

So fixing your design not to require this appears to be the only viable
solution.

-Peter

Apr 1 '06 #3
Peter Hansen <pe***@engcorp. com> wrote:
B. Don't bother trying, because even if the MTU is large enough there is
absolutely no guarantee that the packet will stay intact all the way
through the network anyway (even if you use sendall() instead of send()).
This is true, but I'm generating the message being sent in very small
chunks (often as small as 4 bytes at a time), and typically need to flush a
packet out onto the network after a few dozen bytes. Maybe at most a few
hundred. I don't know of any networks with MTU's smaller than that.
Measurements show a 10-fold improvement in protocol throughput with large
packets vs. small ones. The only question is what's the most efficient way
in Python to generate the large packets.
So fixing your design not to require this appears to be the only viable
solution.


My design is not broken. I'm writing code to drive a pre-existing binary
communications protocol. It is what it is. The functionality I seek
exists at the Unix system call level (writev, sendmsg), but doesn't appear
to be exposed in the Python socket API.
Apr 1 '06 #4
In article <pa************ *************** *@zetafunc.net> ,
Anthony Greene <sy******@zetaf unc.net> wrote:
On Sat, 01 Apr 2006 14:56:02 -0500, Roy Smith wrote:
I've got a bunch of strings in a list:

vector = []
vector.append ("foo")
vector.append ("bar")
vector.append ("baz")

I want to send all of them out a socket in a single send() call, so
they end up in a single packet (assuming the MTU is large enough). I
can do:

mySocket.send ("".join (vector))

but that involves creating an intermediate string. Is there a more
efficient way, that doesn't involve that extra data copy?


Is sendall() what you're looking for?


No. Sendall() is actually what I'm using now. It handles the other side
of the issue; issuing repeated send() calls if the system fragments your
buffer. I'm trying to aggregate lots of small buffers into one large one.
Apr 1 '06 #5
Roy Smith <ro*@panix.co m> writes:
This is true, but I'm generating the message being sent in very small
chunks (often as small as 4 bytes at a time), and typically need to flush a
packet out onto the network after a few dozen bytes. Maybe at most a few
hundred. I don't know of any networks with MTU's smaller than that.
Measurements show a 10-fold improvement in protocol throughput with large
packets vs. small ones. The only question is what's the most efficient way
in Python to generate the large packets.


Probably: build up the packet with cStringIO or with the array module
instead of as a list of small strings. But if you time both versions
I don't think it'll matter much. Python (at least CPython) simply
will not be very fast no matter what you do. The overhead of building
a large string (with ''.join, say) from a bunch of small ones isn't
that big a deal compared with what you already lose in interpreter
overhead running the application.
Apr 1 '06 #6

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

Similar topics

9
7066
by: rhmd | last post by:
I need to create image files (eg bmp or jpeg) of xy scatter graphs (i.e., graphs in which markers denote individual points; the markers need to be small polygons of various sizes, shapes, colors, shadings, etc. and there are thousands on them on each graph). Have been using MS Excel, but its limitations are unbelievable (only whole number sizes, no way around a 56 color palette, only low quality jpeg files so that when I publish the...
9
12788
by: Dr. Colombes | last post by:
What is the easiest way to generate some plots and graphs in Python ? Specifically interested in simple histograms and scatter plots with circles and regression lines. Thanks for your suggestions.
0
4488
by: P Fu | last post by:
I am trying to plot pair using the XY scatter chart in Access and place it into a report. I want my x-axis to have "Age" values and the y-axis to have "Gross Area" values, both pulled using a query I created. Since the chart dialogue boxes only ask for the Y data series with an arbitrary X coordinate of 1, is there any way I can change that? That is, use the "age" values as the x-axis, not the arbitrary 1? Thanks for your help in...
0
1695
by: Dave | last post by:
I have a scatter chart that's based on a SQL Stored Procedure. Procedure works great, but when I apply it to the chart, the X axis returns a series of numbers that I think are record numbers. The value that should be returned is a project number. What am I doing wrong here?
3
3479
by: Joe | last post by:
This probably isn't the right group for this kind of question but I figured I would take a shot... I want to remove points that skew a scatter plot. For example 20 data points are around -75 to 100 on the Y axis but a couple of points are at 1500 and a couple at -500 How would I figure which points should be removed? Of course I want to remove the 1500's and -500's.
8
30479
by: Derek Basch | last post by:
Can anyone give any suggestions on how to make a logarithmic (base 10) x and y axis (loglog) plot in matplotlib? The scatter function doesn't seem to have any log functionality built into it. Thanks, Derek Basch P.S. I suck at math so feel free to make me feel stupid if it is really easy to do :).
2
2541
by: DFS | last post by:
I can't get the Access scatter chart to place the data points correctly, ie at the intersection of their XY position. Is this a bug, or is it me? Thanks
18
2699
by: DFS | last post by:
I posted this question yesterday, and nothing but silence. I looked through cdma in Google, and it seems whenever someone posts questions about scatter charts, they get ignored. So, hopefully, this time, someone will have some brilliant response to share. Starting with the Chart Wizard, I can't get the Access scatter chart to place the data points correctly, ie at the intersection of their XY
4
2059
by: Phil Stanton | last post by:
Is it possible to build a chart where you supply the X & Y Co-ordinates and have the data displayed at that point. To clarify:- Suppose we have a cemetary (Scatter seems inapproporiate here) and have the X & Y co-ordinates of each grave. I want to display the name of the corpse in the correct position Morbid? Actually it is boats in a boat compound.
1
5580
by: kjb034 | last post by:
I have the following macro. It works fine, creating an XY scatter plot in Excel 2003, but when one of my users runs it in Excel 2007, it creates a scatter plot with lines. Why does it do this? I am using "ChartType = xlXYScatter", not xlXYScatterLines. Public Sub CreateChart(ByVal viLabeledSeries As Integer, ByVal viNonLabeledSeries As Integer, ByVal vsWorkbookName As String, ByVal vsPopulationName As String, ByVal vsPrimaryAxisTitle...
0
8428
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
8335
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
8747
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...
0
7356
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
5649
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
4175
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...
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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.