|
On Mon, 26 Apr 2004, David Gibbs wrote: > > Anyone know how much overhead there is in opening & closing a socket? > What do you mean by "opening and closing?" Are you including the time it takes to connect and/or disconnect in that? There is some overhead in calling the socket() API to create a new socket. There's also some overhead in calling the close() API to delete that socket -- but that overhead is relatively small when you compare it to the time it takes to connect to a host and/or disconnect from that host. (and, perhaps confusingly, the close() API both disconnects and deletes the socket descriptor -- depending on the state of the socket...) > I'm in the process of working with a socket interface that requires that > I open a new socket for each request, shut the socket down when I am > done sending, and close the socket when I am done receiving. > > Any thoughts on if this is especially inefficient? It really depends on the application. Take a telnet application for example... the user has to connect/disconnect for each request -- but the requests can last hours, so the connect/disconnect time is insignificant. On the other hand, consider an HTTP application. Each time you switch web pages, the browser will open up potentially dozens of connections to the server, download a few kilobytes of data and disconnect. In that situation a persistent connection saves a bit of time. (Which is why persistent connections are the default in HTTP 1.1) In other situations, TCP just isn't the right choice. I've got an application that sends records from a PC on the manufacturing floor to the iSeries. The project specs call for each 128 byte record to be sent individually to the iSeries. That 128 bytes takes only a fraction of a second to send over the network, but there are 20 programs sending them at any given time, and thousands are being sent every hour. In this case, building a new TCP socket, connecting, sending and disconnecting would be horribly inefficient. Instead, I use the UDP protocol which doesn't require creating new sockets or making connections -- I build one UDP socket and send many records (each as it's own individually tracked datagram) Since UDP is connectionless there's no need for the overhead of connecting & disconnecting.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.