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

Socket Question

AA
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could
be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot
Nov 15 '05 #1
6 2853
TCP is stream based, which means, it doesn't really distinguish between one
big blob of 10MB or 10 blobs of 1MB each or even 1.05million blobs of 1 byte
each.

The reason why "B" might be a good idea is you will put lesser pressure on
your memory manager.

-vJ

"AA" <aa@personal.net.py> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot

Nov 15 '05 #2
cs
there could also be a slowdown if you send too few bytes at once. I used to
have an upload app on c# that if I read one byte at a time from a file and
uploaded it it would run slow, then started tweaking it, sending 1024 bytes,
tehn 2048 (note the numbers dont have to be that, its just some common
numbers to try), I think up to 2048 I would see the speed increase after
that I wouldnt see it increase, it even decreased when I tried something
like 16384 or more.

"Vijaye Raji" <no************@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP12.phx.gbl...
TCP is stream based, which means, it doesn't really distinguish between one big blob of 10MB or 10 blobs of 1MB each or even 1.05million blobs of 1 byte each.

The reason why "B" might be a good idea is you will put lesser pressure on
your memory manager.

-vJ

"AA" <aa@personal.net.py> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function
B) create small arrays with less data and send each one by one (which

could
be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot


Nov 15 '05 #3
You probably want to send in MTU size chunks (i.e. the lowest MTU in the
path). This can make IP more efficient at both ends. I would not suggest
building a 10MB byte array. The network stack breaks down into max datagram
buffers anyway, so larger then max datagram does not really help here.

--
William Stacey, MVP

"AA" <aa@personal.net.py> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot

Nov 15 '05 #4
B, definitely.

You can do something like "A", but it means you're allocating a big chunk of
memory, which is expensive (both in memory use and perf, since you will
flush your cache away when you traverse it). There's also the disadvantage
of having the receiver block on a read for a *long* time (could be 3 minutes
to send 10MB over a 10Mbps ethernet link (assuming I did my math
correctly)). You also might want to be able to restart the transfer if it
got interrupted for some reason.

Finally, the data is going to be chunked into smaller pieces when it goes
over the network anyway. My advice is to pick something reasonable
(something like 4K seems like a good starting point), and then benchmark to
see whether that's a good choice.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"AA" <aa@personal.net.py> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot

Nov 15 '05 #5
Hi,

"AA" <aa@personal.net.py> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could be the better size if you think that this option is the correct)
Create one small array and reuse it for each send.

The maximum bytes you can send at once, is the size of the underlying send
buffer.

You can get the size of the send buffer by calling GetSocketOption with
SocketOptionName.SendBuffer. This is what TcpClient.SendBufferSize property
does.

I'm not sure but I think the default is something like 8k, but since you
don't need to match it exactly, commonly a chunk size of 1024 bytes is used.
The best performace will be when your chunk size <= send buffer size.

A 10MB byte buffer will never be send at once, so creating one large array
is a memory waste.

HTH
greetings

C) Another suggest?

Thanks a lot

Nov 15 '05 #6
AA
Thanks to everyone of you!
"AA" <aa@personal.net.py> escribió en el mensaje
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot

Nov 15 '05 #7

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

Similar topics

2
by: Gonçalo Rodrigues | last post by:
Hi, My setup is the following: I have socket s from which I want to read and write. So I made the following set up: There is a thread whose only job is to read. Any data read (from recv call)...
1
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows...
2
by: djc | last post by:
I read a network programming book (based on framework 1.1) which indicated that you should 'never' use the RecieveTimeout or the SendTimeout 'socket options' on TCP sockets or you may loose data. I...
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...
6
by: roblugt | last post by:
I have what I imagine is a well-known .Net networking problem, but even though I've Googled for some time I've not yet come across a thread where this has been fully explained... There is a...
4
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
6
by: Sean | last post by:
Hi Everyone, My apologies for a somewhat dump question but I am really stuck. I have been working on this code for two days straight I am dont know what is wrong with it. when I run the code, All...
6
by: billiejoex | last post by:
Hi there. I'm setting up test suite for a project of mine. situations, if the socket is closed on the other end or not. I noticed that I can "detect" such state if a call to socket.read() returns...
1
by: =?Utf-8?B?UmFqbmk=?= | last post by:
Dear Sir/Mam, I have written a server code using the Windows Socket API's. Wherein I have created the socket and bound it to a particular IP address and port number. Later I have made the socket...
2
by: Ali Hamad | last post by:
Hello All : A socket question from a networking newbie. I need to create a server that: 1) receive a message from client. 2) check that message and response to it. 3) the client get the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.