473,287 Members | 3,240 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,287 software developers and data experts.

socket packet size = bandwidth?

This may be the dumbest question of all time, but...

When I set the packet size, does it mean ALL packets are that size, no
matter what? Let's say the packet size is 8KB, and I send a 5 byte
"hello", will it cause 8KB of bandwidth, or 5 bytes (plus TCP/IP
packet header, as well, of course).

(Btw, I 'set' the packet size via Socket.BeginReceive(), in the "size"
field = "The number of bytes to receive." Which seems to imply the
answer is YES.)

My concern is that I want to reduce bandwidth... but things are
'nicer' when the packet size is large so that everything comes in one
go, so I just defaulted to that, but, now b/w is an issue.

Zytan
Jul 24 '08 #1
4 7029
This may be the dumbest question of all time, but...
>
All due respect, it is at the very least poorly worded. :)
LOL
If you are asking a question that involves calling Socket.BeginReceive(),
why is your hypothetical case described as "I send a 5 byte 'hello'"? Are
you asking about sending, or about receiving?
Sorry, I meant receiving 5 bytes. Most of my bandwidth is receiving
data, so this is the important part.

(I use Socket.Send(), obviously, to send data, and that takes an array
of byte, byte [], and I make that whatever size it needs to be at the
time, so I assume that this only uses as much bandwidth as is required
for the bytes and the packet header.)
And is the question about a
UDP socket or TCP socket?
TCP. (I know there's extra packets to ensure proper sequencing of
data, I'm ignoring this for now.)
If you are receiving data, you cannot rely on expecting that "everything
comes in one go", even if larger buffer sizes usually allow that to
happen. A successfully completed receive may result in anywhere from 1
byte all the way up to the buffer size actually being received for that
completion.
Right. The buffer size could be 16,384 bytes, and you send me
"hello", which is 5, and I get 5, and that was a success.
I also would not use the word "packet" to describe the size of your
buffer. At best, if you are _sending_ and you are using UDP, the buffer
length passed to the sending method would define the size of the datagram
itself. But "packets" exist at a lower level than that, and the size of
what most people are actually calling "packets" are unaffected by how an
application sends the data.
Right, if I send 100,000 bytes, it could be sent off as 4 KB packets
underneath, regardless that this is presented to me, the programmer,
as though it was sent "all as one".
If you can either clean up the question so that you're describing it more
precisely, or you can post some code that is exactly what you're talking
about, it'd probably be possible to provide a better answer. Based on
what you've asked so far, all I can say is that when you call a sending
method, the method will send exactly as many bytes as you asked it to (*)
and when you call a receiving method, the method will receive any number
of bytes between 1 and the number of bytes you told it are available in
your receive buffer.
Ok, so for Socket.BeginReceive(), if I tell it I want to accept a
16,384 byte buffer from the internet... and some data comes in from
your PC that says "hello", I call Socket.EndReceive() to get the data,
which returns the number of bytes I got. Which would be 5 for
"hello", and I assume that just because the data buffer COULD accept
16,384 bytes, it would have only used 5 bytes of bandwidth (ignoring
packet headers).

Thanks, Pete!

Zytan

Jul 24 '08 #2
On Thu, 24 Jul 2008 13:16:55 -0700, Zytan <zy**********@gmail.comwrote:
This may be the dumbest question of all time, but...
All due respect, it is at the very least poorly worded. :)
When I set the packet size, does it mean ALL packets are that size, no
matter what? Let's say the packet size is 8KB, and I send a 5 byte
"hello", will it cause 8KB of bandwidth, or 5 bytes (plus TCP/IP
packet header, as well, of course).

(Btw, I 'set' the packet size via Socket.BeginReceive(), in the "size"
field = "The number of bytes to receive." Which seems to imply the
answer is YES.)
If you are asking a question that involves calling Socket.BeginReceive(),
why is your hypothetical case described as "I send a 5 byte 'hello'"? Are
you asking about sending, or about receiving? And is the question about a
UDP socket or TCP socket?
My concern is that I want to reduce bandwidth... but things are
'nicer' when the packet size is large so that everything comes in one
go, so I just defaulted to that, but, now b/w is an issue.
If you are receiving data, you cannot rely on expecting that "everything
comes in one go", even if larger buffer sizes usually allow that to
happen. A successfully completed receive may result in anywhere from 1
byte all the way up to the buffer size actually being received for that
completion.

I also would not use the word "packet" to describe the size of your
buffer. At best, if you are _sending_ and you are using UDP, the buffer
length passed to the sending method would define the size of the datagram
itself. But "packets" exist at a lower level than that, and the size of
what most people are actually calling "packets" are unaffected by how an
application sends the data.

If you can either clean up the question so that you're describing it more
precisely, or you can post some code that is exactly what you're talking
about, it'd probably be possible to provide a better answer. Based on
what you've asked so far, all I can say is that when you call a sending
method, the method will send exactly as many bytes as you asked it to (*)
and when you call a receiving method, the method will receive any number
of bytes between 1 and the number of bytes you told it are available in
your receive buffer.

(*) Exception: note that a Socket in non-blocking mode using the
synchronous Send() method may send fewer bytes than you have told it to.
You have to check the return value to see what was actually sent.

Basically, don't tell Socket to send 8K if you don't want it to send 8K.

Pete
Jul 24 '08 #3
On Thu, 24 Jul 2008 14:10:17 -0700, Zytan <zy**********@gmail.comwrote:
[...]
Ok, so for Socket.BeginReceive(), if I tell it I want to accept a
16,384 byte buffer from the internet... and some data comes in from
your PC that says "hello", I call Socket.EndReceive() to get the data,
which returns the number of bytes I got. Which would be 5 for
"hello", and I assume that just because the data buffer COULD accept
16,384 bytes, it would have only used 5 bytes of bandwidth (ignoring
packet headers).
Yes, that's correct. The only real downside for the larger buffer is the
memory consumption locally. Generally speaking, larger buffers provided
to the Socket _improve_ performance, because you have to transition back
and forth between your application code and the network driver fewer
times. Of course, beyond a certain point (16K is a good number) you get
diminishing returns, but up to that point, larger is better.

Obviously, for modern computer systems, 16K is a trivially small buffer in
terms of memory consumption. So you might as well use something about
that size. The biggest things I'd worry about are a) if you were
allocating a lot of these buffers (handling a large number of connections,
for example), and b) keeping the buffer smaller than the threshold for
allocations winding up in the large-object heap (at 16K you'd be well
under that threshold though).

Pete
Jul 24 '08 #4
Yes, that's correct. The only real downside for the larger buffer is the
memory consumption locally.
Right.
Generally speaking, larger buffers provided
to the Socket _improve_ performance, because you have to transition back
and forth between your application code and the network driver fewer
times.
Yes.
Of course, beyond a certain point (16K is a good number) you get
diminishing returns, but up to that point, larger is better.
Understood.
Obviously, for modern computer systems, 16K is a trivially small buffer in
terms of memory consumption. So you might as well use something about
that size.
I will do that.
The biggest things I'd worry about are a) if you were
allocating a lot of these buffers (handling a large number of connections,
for example), and b) keeping the buffer smaller than the threshold for
allocations winding up in the large-object heap (at 16K you'd be well
under that threshold though).
I only have one such buffer, so it's not a big deal.

Thanks for the tips, Pete!! :)

Zytan

Jul 25 '08 #5

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

Similar topics

30
by: Richard | last post by:
Level: Java newbie, C experienced Platform: Linux and Win32, Intel Another programmer and I are working on a small project together. He's writing a server process in Java that accepts input...
4
by: Stephan Steiner | last post by:
Hi I have a networking application that periodically needs to go into sleep mode (from an application point of view, I'm simply suspending the receiver thread until it's time to start listening...
3
by: Stephan Steiner | last post by:
Hi I have a small program listening to UDP broadcast datagrams that are periodically sent out. It will stop listening for a certain period if either a sufficient number of packets has been...
0
by: Stephan Steiner | last post by:
Hi The project I'm currently working on involves sending large UDP broadcasts. As the .NET framework already provides an easy facility for sending and receiving UDP packets I thought it was a...
12
by: David Sworder | last post by:
Hi, I'm writing an application in which a client (C#/WinForms) and server (C#/service) interact with one another. The client establishes a "session" with the server but for scalability reasons...
5
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
2
by: Macca | last post by:
Hi, My application uses an asynchronous socket server. The question I have is what i should set my socket server buffer size to. I will know the size of each data packet sent across the...
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
0
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.