WINDOWS???????п??????????????
???????????? ???????[ 2013/8/6 10:47:39 ] ????????
???????????£?????????????1M???????
??????????????п????????????2G????????????????????ж?????2048?????
??????????浱?????????????????????????????????????????С??
????????????????????????????С??????????С????????????Щ????
?????罫???????С???512K?????????????????4096??????
?????????????????????????п???????????????2GB??????????????
?????????????????64GB??????棬??????????????仹??4GB??????????????????2GB??
??????????????????????????????????????????????????????????÷??????棬????????????????????????????汻????????????????????
??????????????????????????????????????????????????????
??????Windows??д?????????????Fork??2000???????????????????????
????????????????????windows32λ????????????????????????????2G??????????????????StackSize?1024K??1M????????????????????2000???2000*1024K=2G(?????????????????????
????MSDN????
????“The number of threads a process can create is limited by the available virtual memory. By default?? every thread has one megabyte of stack space. Therefore?? you can create at most 2??028 threads. If you reduce the default stack size?? you can create more threads. However?? your application will have better performance if you create one thread per processor and build queues of requests for which the application maintains the context information. A thread would process all requests in a queue before processing requests in the next queue.”
??????????2000???????
??????????????CreateThread????????С????StackSize??????
#define MAX_THREADS 50000
DWORD WINAPI ThreadProc( LPVOID lpParam ){
while(1){
Sleep(100000);
}
return 0;
}
int main() {
DWORD dwThreadId[MAX_THREADS];
HANDLE hThread[MAX_THREADS];
for(int i = 0; i < MAX_THREADS; ++i)
{
hThread[i] = CreateThread(0?? 64?? ThreadProc?? 0?? STACK_SIZE_PARAM_IS_A_RESERVATION?? &dwThreadId[i]);
if(0 == hThread[i])
{
DWORD e = GetLastError();
printf("%d
"??e);
break;
}
}
ThreadProc(0);
}
??????????????????
??????????????????????????????client???????????????????????????2000????????????????CPU?????????????£??????????£?
????The "one thread per client" model is well-known not to scale beyond a dozen clients or so. If you're going to be handling more than that many clients simultaneously?? you should move to a model where instead of dedicating a thread to a client?? you instead allocate an object. (Someday I'll muse on the duality between threads and objects.) Windows provides I/O completion ports and a thread pool to help you convert from a thread-based model to a work-item-based model.
????1. Serve many clients with each thread?? and use nonblocking I/O and level-triggered readiness notification
????2. Serve many clients with each thread?? and use nonblocking I/O and readiness change notification
????3. Serve many clients with each server thread?? and use asynchronous I/O
????--------------------
????????Win32????????2GB?????????????????2GB?????????á?
????Linux????λ1GB?????????λ3GB????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11