|
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");
|
|
|
|
|
after doing this
error C2664: 'fopen' : cannot convert parameter 1 from 'LPCTSTR' to 'const char *'
|
|
|
|
|
impossible.
post a relevant piece of code please.
|
|
|
|
|
toxcct wrote: impossible.
Yes, if UNICODE is defined.
|
|
|
|
|
CString strFName = m_FName + CString(data);
FILE* fp = fopen((LPCTSTR)strFName,"wb");
Its giving error
error C2664: 'fopen' : cannot convert parameter 1 from 'LPCTSTR' to 'const char *'
|
|
|
|
|
Use _tfopen() instead.
"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
|
|
|
|
|
Hiya guys i seem to have this rather annoying problem, i'm trying to finish a 9 question assignment on C, however i have managed to finish 7 of those but am stuck on two of them. I tried finding hints/tips on the internet as well as try to understand the topic from library books but i still can't seem to understand the whole thing. Anyways i stumbled upon this site and i really need your help. If anyone can solve these two questions for me i would really appreciate it.
1- The day of the week for any given date can be calculated using Zeller's congruence, which can be neatly programmed into a computer. The technique is detailed below.
Assume that "year", "month" and "day" have been given as three integers, for example 1965, 8, 23 respectively for August 23rd 1965. The calculation continues.
if month < 3 then
month=month+12
year=year-1
end if
Then
nd=((13*month+3)\5+day+year+year\4-year\100+year\400)mod 7
The sign \ is used to indicate integer division (ignore the remainder) – to achieve the desired result simply use integers for everything (some languages, C not being one, actually have an ‘integer devision’ method). The "mod 7" terms means find the remainder after dividing by 7. Note: in C Mod is calculated in C using the ‘%’ , ie 16%8 is 16 mod 8 = 0
The result, nd, gives the day: 0 is Monday 1 is Tuesday etc. T
he formula is (of course!) year 2000 compliant, but only extends back to the Gregorian calendar revision, which occurred at different dates in different countries.
Ask the user to enter the day, month & year then, calculate ‘nd’ and then use this value in a switch statement where the ‘cases’ are enumerated variables defined for the days to display the relevant day of the week.
2- Unions:
You are required to create a union containing the various integer and float types and an array of unsigned chars.
The size of the array of chars should be the number of bytes used for storage of the largest variable type
Assign values to the various members of the union and then display the values of the bytes used for storage.
Extend the program from part 1 such that the bytes are displayed using a single function which is passed your union & the no of bytes for the type assigned.
Using your union from above ask the user to enter an integer value. Display the bytes used for storage.
Swap the bytes used in storage and then display the new byte sequence and the ‘new’ integer value. You should do this for ALL integer types > one byte in size.
Once again if anyone could help me with this i would really appreciate it, and i look forward to hearing from anyone soon. Thanx a lot.
Hayan
|
|
|
|
|
Answer to your first Question::
int day = 12, month = 1, year = 1984;<br />
<br />
if(month < 3)<br />
{<br />
month = month + 12;<br />
year = year - 1;<br />
}<br />
<br />
int nd = ((13 * month + 3) / 5 + day + year + year / 4 - year / 100 + year / 400) % 7;
now use nd as you want it will contain 0 to 6 for Monday, Tuesday,...,Sunday
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
I am not getting your second question.
Explain it again in brief
Manish Patel.
B.E. - Information Technology.
|
|
|
|