Sorry for how long it took to reply to your mail.  Hope it wouldn't appear to have been left unnoticed!  :-)
HI,
  I have done a few IOCP Winsock application, which work fine, but want to as a couple of things:
 
I have only designed using for TCP/IP protocol, and for network, and internet access. I learned from the 'Network Programming Form Microsoft Windows" book (second edition), and it explains the IOCP really well, I have in the past read with interest some different comments, and wondering what people thought of these?
 
The NumberOfConcurrentThread within the CreateIOCompletionPort(..) indicates the number of threads allowed to execute concurrently to avoid thread context switching, which seems logical to me. So setting it to 0, will inform the processor to allow as many threads to run as processors.  
Well, the rule of thumb here is to have 2 times the number of CPUs on your machine IOCP worker threads.  With IOCP, the system issues IOCP services to the thread which had been doing it most recently.  Thus, if your thread is awakened to service an IOCP request, and it finishes up before its time slice expires, and there's another request available to service, it gets a chance to service them.  This means less context switch, and more performance.
Now the worker threads depends on the type of application. In my next application there will be database acess from users connected to the server. So, It also mentions it is possible to have 'x' amount of worker threads created, but only one will be accessed on the Completion port at one time. But the handy part is that , which in my case, if database is being accessed, then there is a chance that the worker thread be suspended doing its thing with the database, and passing information to the client application. In this case, another worker thread will be allowed to operate in its place, which also sounds fair enough. So in my application, because of using databases, I am thinking of creating say, 5-6 worker threads. Even though only one will accessing the IOCP routine, another one can take over if it becomes busy with database access. I am only planning to post one WSARecv(..) per socket handle, so not much chance of receiving blocks at different times.  
You need to notice a subtle point.  No matter how many threads you have, the system can execute only one thread per CPU, so in fact the impression that "another one can take over if it becomes busy" is not quite correct.  Maybe letting it run and service other requests as well can lead to better performance. 
Also, I understand that Per I/O operation structure, as it is only used for sending and receiving, but, when a connection is established from a client,  a WSARecv(..) is posted, which has to have a pointer to a Per I/O structure. And within the IOCP routine, the pointer to this buffer is returned with the data in it, then another WSARecv(..) is posted within the worker thread. As I can see it, then while the socket connection is live, each connectoin will alway have a Per I/O attatched to it. So if I have 500 connections, each one will have its own Per I/O structure , as it is passed through the WSARecv(...). Is this correct?? 
Yes.  As their name says, per I/O structures exists one per each outstanding I/O operation.  A big performance boost is gained if you don't allocate each per I/O structure when you want to issue an I/O.  It would be mich better if you preallocate a big pool of per I/O objects, and just grab one from the pool when you want to issue an I/O, and put it back on the pool when an I/O finishes.

---------
Ehsan Akhgari

www.farda-tech.com
List Owner: [email protected]

[Email: [EMAIL PROTECTED]]
[WWW:
http://www.beginthread.com/Ehsan ]

The answers to life's questions lie inside you. All you need to do is look, listen, and trust.

_______________________________________________
msvc mailing list
[email protected]
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for 
subscription changes, and list archive.

Reply via email to