Click here to Skip to main content
15,908,115 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How do you fix code that works on everything but the listview you need? Pin
Mike O'Neill27-Jan-07 12:53
Mike O'Neill27-Jan-07 12:53 
QuestionInvoke another exe from currently running exe Pin
kiranin26-Jan-07 17:36
kiranin26-Jan-07 17:36 
AnswerRe: Invoke another exe from currently running exe Pin
ThatsAlok26-Jan-07 19:32
ThatsAlok26-Jan-07 19:32 
QuestionCOM in VC++ Pin
deeps_cute26-Jan-07 17:02
deeps_cute26-Jan-07 17:02 
QuestionVisual C++ MFC WinSock 2 Reference Pin
Obi Wan 226-Jan-07 13:50
Obi Wan 226-Jan-07 13:50 
AnswerRe: Visual C++ MFC WinSock 2 Reference Pin
Mark Salsbery26-Jan-07 14:03
Mark Salsbery26-Jan-07 14:03 
GeneralRe: Visual C++ MFC WinSock 2 Reference Pin
Obi Wan 227-Jan-07 4:47
Obi Wan 227-Jan-07 4:47 
GeneralRe: Visual C++ MFC WinSock 2 Reference Pin
Mark Salsbery27-Jan-07 7:30
Mark Salsbery27-Jan-07 7:30 
Obi Wan 2 wrote:
In your example, 1000 threads serving 1000 connections makes a strong case for thread pooling (IOCP).
It would be equally pointless to inherit the overhead of thread pooling for a single connection.
Where do you see the break-even point? 10? 100?


To me, the break-even point is at the number of processors on the machine. There's no reason
to have more threads than can be run concurrently. I get good results with IOCP and the number
of threads in the pool equal to number-of-processors * 2. This way there's a thread available
to start processing until it needs to wait for another thread to finish using a a relatively
slow-to-access shared resource (a database in my case). When another thread finishes, the next
thread is already waiting at the code that accesses the resource. I haven't yet been able to
thoroughly test performance using 1, 2, ... threads-per-processor to determine the best
performance but it's something that should be done.

I agree for a single connection an IOCP with a pool of threads would be pointless, unless you're
using the IOCP for other things besides socket I/O. IOCPs make a handy semaphore-like object
with no release count limit, but that's another topic altogether.

There's nothing wrong with using an IOCP with just one thread. If, for example, an app does many
socket sends that don't require a reply, then putting the messages in overlapped buffers and
sending using the IOCP can save coding time since IOCP has implemented queueing for you. The
one thread just cleans up the buffers when the IOCP is done with them (by deleting or maybe
returning them to a buffer pool). There's also the advantage in this scenario of being able
to turn off the socket's send buffering, since overlapped buffers hold the data - no need to
do an extra copy to the socket's send buffer.

Obi Wan 2 wrote:
Overlap, asynchronous and non-blocking kind of address the same issue--that being performance.
What is the case to be made for each technique? Other than the thread pooling issue, is there a
performance benefit over using non-blocking sockets and periodically polling them?


I would say that it depends on the architecture of the code, specifically how threads are being
used. A single-threaded application using blocking sockets would perform poorly and if it had
a UI, the user experience would be horrible. Overlapped/asynchronous operations can help by
allowing processing to continue immediately after a socket operation is called. When the
operation finishes at a later time then the app is notified. Because the Windows Sockets
implementation is capable of being used event-driven, I think polling is completely unnecessary,
a waste of CPU cycles, and inefficient...which leads to the 3rd topic...

Obi Wan 2 wrote:
What can you tell me about select, WSAAsyncSelect, etc.?


First, the only difference between WSAAsyncSelect and WSAEventSelect is the method that the app
is notified that a particular socket event occurs. WSAAsyncSelect uses regular Windows
messages (good for single-thread apps) and WSAEventSelect uses an event synchronization object
(good for multi-threaded apps). Waiting for FD_READ events is particularly useful because it
eliminates the need to poll for received data.


It's typically recommended that one thread be used for socket I/O. Sockets are not thread-safe
(although reading and writing simultaneously to a Windows Socket generally works, it's not
documented as being safe) so multiple threads would end up waiting to use the socket anyway.

For maximum efficiency using TCP it's most important to keep the receive buffer flushed,
otherwise performance drops significantly. If an app isn't able to process incoming data as
fast as it is received then the data should be queued/buffered for later processing by another
thread to allow the I/O thread to continue receiving data. Actually that applies to UDP as well
except that with UDP, if you don't receive datagrams fast enough, it only affects the receiving
end. With TCP the sender is affected because it knows the receiving end can't accept data so it
has to wait.


For more specific implementation details, I guess it comes down to what type of communication is
going on. Text data to/from a database requires a relatively simple implementation. Real-time,
high bandwidth data requires something more sophisticated. IOCPs are great for managing large
numbers of connections, such as with a large organization's database server or an HTTP server.

I'm no expert on this stuff. All my comments are based on experience - A major portion of my
application suite is real-time streaming of video/audio/device-control data mixed with database
communication. I've had the (un?)fortunate pleasure of re-writing my communication code
several times over the past few years trying different combinations of socket operations and
thread models.

Mark
QuestionCListView; getting rid of spurious horizontal scrollbar [modified] Pin
Joe Woodbury26-Jan-07 12:34
professionalJoe Woodbury26-Jan-07 12:34 
AnswerRe: CListView; getting rid of spurious horizontal scrollbar Pin
Ravi Bhavnani26-Jan-07 12:59
professionalRavi Bhavnani26-Jan-07 12:59 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Joe Woodbury26-Jan-07 13:06
professionalJoe Woodbury26-Jan-07 13:06 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Ravi Bhavnani26-Jan-07 13:09
professionalRavi Bhavnani26-Jan-07 13:09 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Joe Woodbury26-Jan-07 13:23
professionalJoe Woodbury26-Jan-07 13:23 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Ravi Bhavnani26-Jan-07 13:27
professionalRavi Bhavnani26-Jan-07 13:27 
AnswerRe: CListView; getting rid of spurious horizontal scrollbar Pin
Mark Salsbery26-Jan-07 13:54
Mark Salsbery26-Jan-07 13:54 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Joe Woodbury26-Jan-07 15:12
professionalJoe Woodbury26-Jan-07 15:12 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Mark Salsbery26-Jan-07 16:27
Mark Salsbery26-Jan-07 16:27 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Joe Woodbury27-Jan-07 11:34
professionalJoe Woodbury27-Jan-07 11:34 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Mark Salsbery27-Jan-07 11:42
Mark Salsbery27-Jan-07 11:42 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Joe Woodbury27-Jan-07 12:24
professionalJoe Woodbury27-Jan-07 12:24 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Mark Salsbery27-Jan-07 11:49
Mark Salsbery27-Jan-07 11:49 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Joe Woodbury27-Jan-07 12:32
professionalJoe Woodbury27-Jan-07 12:32 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Joe Woodbury27-Jan-07 13:01
professionalJoe Woodbury27-Jan-07 13:01 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Mark Salsbery27-Jan-07 15:35
Mark Salsbery27-Jan-07 15:35 
GeneralRe: CListView; getting rid of spurious horizontal scrollbar Pin
Joe Woodbury27-Jan-07 17:41
professionalJoe Woodbury27-Jan-07 17:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.