|
Jeff Prosise's book [^] may help.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
keyto wrote: I could not understand the theme of the code can you make me understand the code?
Exactly which statement is troubling you?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
What do you want to know?
|
|
|
|
|
Hai,
i am working with IOCP server and normal socket Client. i have created 2 threads in my server side(in a thread pool). and trying to connect more number of clients using threads.
But Only 3969 clients are getting connected at a time....
as of use in IOCP we can connect 65000 clients .....but atleast i want 10,000 clients to connect.
What is the issue over here...
reply me,
Mani
Born to win...!
|
|
|
|
|
How many threads are created in total ?
D.Mani wrote: and trying to connect more number of clients using threads.
Do you have one thread that gets created for each clients that connect ?
|
|
|
|
|
hai,
thanks for reply, here is my code :
1.for (int ii = 0; ii < nNoOfThreads; ii++)
2.{
3.b = CreateConnectedSocket(&(pThreadInfo[ii].m_Socket),"192.168.60.206", nPortNo);
4.if(b)
5.{
6. pThreadInfo[ii].m_nThreadNo = ii+1;
7. p_hThreads[ii] = CreateThread(NULL, 4096, WorkerThread,(void *)(&pThreadInfo[ii]), STACK_SIZE_PARAM_IS_A_RESERVATION, &nThreadID);
8.}
in for loop "nNoOfThreads= 4500",
and the 3rd line i am creating socket, and trying to connect with passed parameters.
now..each 4500 sockets has o create,
den create thread will take care of message send and receving...
now the issue is only 3969 sockets are created... and the 3969 threads are created.
Mani.
Born to win...!
|
|
|
|
|
Do you know what a thread is ? Do you understand that you need some resources to manage one single thread ? Do you also understand that switching between different threads take some time, so imagine what will happen if you have to switch between 10000 threads. Multithreading is achieved by time slicing: your processor will work on one thread for a small amount of time, then switch to another thread for another small amount of time and so on... So, guess what happens when you have 10000 threads ? Nothing works anymore because there are just too much threads to be handled.
D.Mani wrote: What is the issue over here...
You are just asking too much from the system. There not enough memory to manage all the threads that you are creating. This should ring a bell that your design is just plain wrong.
Some people already told you that creating so many thread is a bad idea. Now you see the reason.
|
|
|
|
|
hai,
i want to check whther my server is stable and able to serve more number clients...approximately 10,000 clients...
all of them are trying to access this server at a time...
So, i need to give simultanoues access to the server..so i decided to use threads....for creating that many connections at a time....
each and every thread will start connecting to the server..,
i am not goin this way...without any aim...please understand this....
Born to win...!
|
|
|
|
|
No, really you ARE going without aim.
With an IOCP, you can service 10s of thousands of connections with just a few threads.
If you think every connection needs a thread, or that it's even possible for 10,000 threads
to simultaneously run on a machine with less than 10,000 CPUs, then you really don't understand
threads at all.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I think he's actually trying to emulate clients using a single thread per client. However, he's running into the same problem - you can't create huge numbers of threads in a single process because you run out of virtual memory. I think he's falling foul of the fact that even though he's only asking for a 4KB stack reserve, he's actually getting 64KB as that's the minimum that Windows VirtualAlloc will reserve. He's therefore blowing 256MB of virtual address space on thread stacks out of the 2GB available, presumably the rest being allocated by some other data structures and by the amount of code loaded into the process.
This is assuming that he's not actually blowing some other system data structure (handle table?) first.
Large-scale testing of servers is pretty tricky without actually getting thousands of people together each operating their own client. Right now my thin-client application server only has a Windows port of the client which can be automated, so I have one process per client (and it's a console-mode process, so one window per client). The practical limit is about 600 clients per test box, which is consuming about 70% of a 2 x Xeon 5150 box's CPU power due to a few odd timing loops and all the overhead of console mode output being RPCs to the CSRSS process which actually draws the windows.
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
Mike Dimmick wrote: Large-scale testing of servers is pretty tricky without actually getting thousands of people together each operating their own client.
Definitely. Even then, it's hard to push the server software very far since the network
(and any other device I/O, like a DB on a harddisk) will probably be the first bottleneck.
Mike Dimmick wrote: I think he's actually trying to emulate clients using a single thread per client.
Clients. My bad Still, the same principles apply and it's been discussed repeatedly.
Great replies, BTW, thanks!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
This is the third time I've answered this.
The IOCP is so you don't have to create a thread for every connection.
You can try, but it's not going to happen. 1000 connection threads takes over a GB of RAM
by default, all of which will spend 99.999999% of the time doing nothing.
Did you read the articles at the links I provided twice before?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
When using I/O completion ports you are supposed to have a much smaller pool of threads. The operating system only runs as many threads concurrently as are necessary to keep the CPUs busy. I haven't got space here to explain it fully, you should see "Programming Server-Side Applications for Windows" for more information, but basically when a thread calls GetQueuedCompletionStatus, it will block. When an I/O request completes, and the number of threads already running is less than the number of CPUs, Windows will unblock the first waiting thread. Threads that complete their request and call GetQueuedCompletionStatus again go back to the head of the queue (this should keep the thread's data variables 'hot' in the processor cache).
The magic is this: if a thread that is associated with a completion port blocks for some other reason, Windows looks to see if there are now fewer threads than the number of CPUs running, and if so, it releases another one. On the whole, this keeps the number of threads down and therefore the number of context switches between runnable threads minimized (which is time spent unnecessarily switching between threads that could otherwise have been used for useful work).
Each new thread requires its own stack. The actual stack size reserved depends on compiler switches, by default, 1MB per thread. Multiplying up you can see that 3,969 threads is about 4GB of reserve. You're blowing your entire virtual address space on thread stacks. That's the practical limit of how many threads you can create in one process.
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
What does LPBITMAPINFOHEADER does?
|
|
|
|
|
holds the address of a BITMAPINFOHEADER struct.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
It points to a BITMAPINFOHEADER structure.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can we test (unit test) C++ (not VC++) project using VC++ Unit Test project.
More details: I have a project written in C++ (standard). Now i want to test it.
I create a VC++ Unit Test project, but i can not make link between this Test project with my C++ project (can not call functions (defined in my C++ project) in test methods)).
Hope some one can help me.
Thank you.
LC
|
|
|
|
|
Hi all,
LPCSTR data;
CString m_FName;
CString strFName = m_FName + data;
When i write this piece of code it works fine in vc++ 6.0 compiler. But when i write this in VC 2005 it gives error:-
" error C2679: binary '+' : no operator found which takes a right-hand operand of type 'LPCSTR' (or there is no acceptable conversion)"
How to resolve this....
Thanks in advance........
|
|
|
|
|
CString strFName = m_FName + CString(data);
|
|
|
|
|
now next error is
FILE* fp = fopen(strFName,"wb");
error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to 'const char *'
|
|
|
|
|
Probably you need
FILE * fp = _tfopen(strFNAME, _T("wb"));
or to choose an ANSI build.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
No it gives same error..........
|
|
|
|
|
CPallini wrote: FILE * fp = _tfopen(strFNAME, _T("wb"));
The compiler was complaining about the first argument.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I know.
Probably he is making a UNICODE build with code previously built as ANSI. Now CString 's LPCTSTR cast operator turns out to be LPCWSTR . The suggested use of _tfopen fixes that problem (using a generic text mapping approach) but then we need to be consistent and use also _T() on the second argument.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
FILE* fp = fopen((LPCTSTR)strFName,"wb");
|
|
|
|