Re: Socket Send
- From: Brian C <brianc@xxxxxxxxxxxxxxxxxxx>
- Date: Sat, 18 Mar 2006 04:31:37 GMT
Brian C wrote:
David Schwartz wrote:
"Brian C" <brianc@xxxxxxxxxxxxxxxxxxx> wrote in message news:MUqSf.20849$nB6.4616@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxThe sockets are blocking. I did do some reading and saw that I should be sending/reading in 4k increments, so I figured I'd start blocking the data on the server side, which would mean I'd have to be locking a mutex for a buffer and having a seperate thread running every say half a second to flush whatever data is in the buffer. I've done it before on a process that reblocks the quotes and sends them into the mainframe trading systems, and it works exceptionally well, but I'm not to keen on doing it again.
Any ideas on how to get rid of that delay? The delay isn't predictable, but it happens roughly every 10-30 messages.
Are your sockets blocking or non-blocking?
Your read algorithm is not very good. You should *always* call 'read' for at least 4,096 bytes. If you get "too many", you can process them later *without* having to call read again, so that's a *win*. Do not try to read the header separately -- same reason.
DS
Ok, so basically, you're suggesting:
1) Set the socket to non-blocking.
2) Do the select(), see there is data.
3) Do a read for 4k. If 4k is not available, it'll exit out right away.
That should work. It'll take some finagling because right now I have 1 function that does the read() and 1 that does the write(), and every process I have that does sockets uses them. So, I'd like to keep it w/ 1 read() & 1 write(), but I dont want to change every call, but I'll look into that.
Would it be beneficial to also try to block it in 4k increments before doing the write() as well?
I'm just curious though...the typical time for both reads is .000004 seconds, which seems like a reasonable time in my opinion. It may be inefficient to do 2 reads, but, the response time seems good to me. I'm just curious as to why sometimes it would be that fast, then sometimes it would be .15 seconds? And it's not because I'm doing multiple read()'s. I logged each return code of the read(), and I saw it took 1 time about 10-15 read()'s to read in the entire message (was getting small chunks each time), and it still completed in .000002 seconds.
Thanks for your time and reply!
Let me clarify.
I'm just curious as to what benefits reading a 4k block does? Is this something internal to the TCP/IP stack or?
Thanks again.
.
- Follow-Ups:
- Re: Socket Send
- From: David Schwartz
- Re: Socket Send
- References:
- Socket Send
- From: Brian C
- Re: Socket Send
- From: David Schwartz
- Re: Socket Send
- From: Brian C
- Socket Send
- Prev by Date: Re: Socket Send
- Next by Date: Re: linker question
- Previous by thread: Re: Socket Send
- Next by thread: Re: Socket Send
- Index(es):
Relevant Pages
|