socket sin procesar que omite los encabezados tcp / ip

I have a 2 programs that are communicating via sockets on the same computer. Currently 1.6 million bytes is taking about 7 seconds to transfer using TCP/IP. I need to make it fast.

If I use a raw socket instead, and ignore the TCP/IP headers, then this should increase the speed? Is there anything else I can do to increase speed? Is the SOCKET_RAW option a straight copy or does it do anything else?

preguntado el 27 de agosto de 11 a las 16:08

Can you confirm that you're saying it takes seven seconds to transfer a megabyte and a half? Like, one floppy disk worth of data? -

yea it is 1.6MB. I am investigating to see what is going on. -

There's no benefit (and possibly some drawback) to dividing the chunk size by two. Just always try to recv() as many bytes as you have room for in your buffer (or the number of bytes of data left to receive, whichever is smaller). (It could be that the divide-by-two mechanism is causing your code to recv() 1 byte at a time near the end of the transfer, which would certainly slow things down) -

4 Respuestas

1.6MB shouldn't take 7 seconds using "normal" TCP/IP - certainly not on the same machine! That suggests you've got inefficient code somewhere. I'd address that before trying to do anything "special" in terms of the networking.

EDIT: I've just written a short C# program on a netbook, and that transfers 2MB (generating random data as it goes) in 279ms. That's with no optimization. Unless you're running on a machine from the 1980s, you should que probar definitivamente be getting better performance than that...

Respondido 27 ago 11, 21:08

You know, I read it as 1.6 GB rather than MB at first. You are quite right--7 seconds for 1.6 MB implies something is broken, and it's not TCP. - John Zwinck

Yeah ... sounds like a case of "select isn't broken" - Brian Roach

Thanks. I discovered the issue. - eat_a_lemon

@eat_a_lemon: It's typically good form at this point to explain (either in a self-answer or in the question) to help others who might have the same problem. - Jon Skeet

Try using Unix Domain Sockets instead.

Respondido 27 ago 11, 20:08

To get that poor of performance, you are doing something very inefficient. Perhaps the i/o operations are single byte?

Changing to raw sockets is a bad idea. To get reliable communication, you'd then have to add some sort of data checking, sequencing, etc., etc.: everything that TCP does for reliability.

If the purpose is to transfer data from one process to another on the same machine, use shared memory and a mutex to synchronize access. Of course this is not a good solution if the programs will eventually have to run on separate machines.

Respondido 27 ago 11, 22:08

No, using raw IP sockets is definitely not a good idea. Using a unix-domain socket might be ligeramente more efficient, but I doubt it's going to solve your problem. You clearly have another problem. Perhaps it is your application-level protocol which is inefficient?

Respondido 27 ago 11, 22:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.