| | |
C++ Server: Multi-thread VS Single-thread
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2007
Posts: 4
Reputation:
Solved Threads: 0
Hi guys,
I startin the project of a (web) server in c++ and i want to able to manage about 1000-2000 clients.
I have been reading alot about Single-thread VS Multi-thread server and i wanna know what u guys think about it.
I do not plan on using one-thread-per-client because i have heard that its too slow for 1000+ clients.
On the begin , i was 100% about using about 5 threads , by service:
1 for the Window Console (so the user can see its information without freezy the window)
1 for sending data
1 for receving data
1 for Accepting new clients
1 for computing the ugly processes (AI)
But then I heard about ppl sayin that have done webservers with only 1 thread (3 in my case, cause 1 for the window, 1 for acceptin new clients and 1 AI, Receving, Sending data), and i came up with the thought that if i do only use 1 thread for Receive,Sending and AI I wouldnt need to Lock/Unlock so much data (in those 3 processes). This could save alot of the processor's time, i guess.
What i wanna know is that, would u guys try to put the Receive,Sending and AI in just 1 process?
and
(Even though i believe dont, i need to make sure
Would the access to the database (mysql in my case) LOCK my thread for a couple ms? or its just like another function call?
Thanks alot for the help =)
Marcosedu
I startin the project of a (web) server in c++ and i want to able to manage about 1000-2000 clients.
I have been reading alot about Single-thread VS Multi-thread server and i wanna know what u guys think about it.
I do not plan on using one-thread-per-client because i have heard that its too slow for 1000+ clients.
On the begin , i was 100% about using about 5 threads , by service:
1 for the Window Console (so the user can see its information without freezy the window)
1 for sending data
1 for receving data
1 for Accepting new clients
1 for computing the ugly processes (AI)
But then I heard about ppl sayin that have done webservers with only 1 thread (3 in my case, cause 1 for the window, 1 for acceptin new clients and 1 AI, Receving, Sending data), and i came up with the thought that if i do only use 1 thread for Receive,Sending and AI I wouldnt need to Lock/Unlock so much data (in those 3 processes). This could save alot of the processor's time, i guess.
What i wanna know is that, would u guys try to put the Receive,Sending and AI in just 1 process?
and
(Even though i believe dont, i need to make sure
Would the access to the database (mysql in my case) LOCK my thread for a couple ms? or its just like another function call?Thanks alot for the help =)
Marcosedu
Last edited by WolfPack; May 14th, 2007 at 7:18 pm. Reason: Removed the unnecessary bold formatting.
•
•
Join Date: May 2007
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
I think a web server would be better coded in another language -- probably php or even C#, which are designed for that sort of stuff.

Yeah ... i know there is "easer" ways to do it on other language...
Im doin the client in Java...
The thing is that i wanna that my server to be able to manage as many clients as possible (once i finish it, i ll test and set a limit so the server dont crash). For that reason, i plan on doin it on C++.
Thats why i made this post... to now what ppl think that would be the fastest way.
Tks anyway=)
Last edited by MarcosEdu; May 14th, 2007 at 1:54 pm.
worst-case scenario -- you will need a computer with lots of horse power, probably multiple processors to handle that many clients all at the same time and linux os is better at that then MS-Windows. I have no experience writing web servers, so I can't really give any more advice. I would think you will get better answers in the Web Development board.
Last edited by Ancient Dragon; May 14th, 2007 at 1:53 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Not PHP, its basically used for generating dynamic content. Developing a full fledged server is not something it was made for. C# yes possible but most of them are made in C++ and Java.
As for the threads, the idea of the web server running with just one thread is plain crazy. You need to accept requests along with servicing them at the same time returning responses. Plus spawning a new thread for each request is much more recommended than creating a process for each client request(the way it is done in JSP and Servlets). Starting from scratch would be kind of a daunting task. Take a look at some of the open source web servers written in C++ to get a gist of how things are done.
> Thats why i made this post... to now what ppl think that would be the fastest way.
The fastest way would be to use an existing server or build up on its functionality if you require customized features.
As for the threads, the idea of the web server running with just one thread is plain crazy. You need to accept requests along with servicing them at the same time returning responses. Plus spawning a new thread for each request is much more recommended than creating a process for each client request(the way it is done in JSP and Servlets). Starting from scratch would be kind of a daunting task. Take a look at some of the open source web servers written in C++ to get a gist of how things are done.
> Thats why i made this post... to now what ppl think that would be the fastest way.
The fastest way would be to use an existing server or build up on its functionality if you require customized features.
Last edited by ~s.o.s~; May 14th, 2007 at 1:55 pm.
I don't accept change; I don't deserve to live.
•
•
Join Date: May 2007
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
Not PHP, its basically used for generating dynamic content. Developing a full fledged server is not something it was made for. C# yes possible but most of them are made in C++ and Java.
As for the threads, the idea of the web server running with just one thread is plain crazy. You need to accept requests along with servicing them at the same time returning responses. Plus spawning a new thread for each request is much more recommended than creating a process for each client request(the way it is done in JSP and Servlets). Starting from scratch would be kind of a daunting task. Take a look at some of the open source web servers written in C++ to get a gist of how things are done.
> Thats why i made this post... to now what ppl think that would be the fastest way.
The fastest way would be to use an existing server or build up on its functionality if you require customized features.
Hum.. i have some basic coding goin on alrdy and i guess im rdy to build the server...
But, so u think that if im goin to build the server, i should use 1 thread per client?
I know its recomended.. but they also think that u ll have a SUPER-ULTRA server to take care of that many threads...
Did you try it alrdy? and..
I plan on running this server on something like a P4 3.0g with 1024 or 2048mb ram.
Isnt it bad having like 1000 threads opened at same time? (maybe cause of too many locks/unlocks, waits, and stuff like that caused by the shared data)
I dint tell much about the server... it ll be a game server, basicly accepting conections, receveing data, sending and compute the game stuff.
once again, tks for the replys =)
> Did you try it alrdy?
No, I haven't as such any practical experience with server development, just a bit of knowledge about servers here and there.
> Isnt it bad having like 1000 threads opened at same time?
Its better than having 1000 processes running at the same time. Clients have to be serviced -- threads or processes, take your pick. And believe me, they don't call threads lightweight processes for no reason.
> I dint tell much about the server... it ll be a game server, basicly accepting conections, receveing data, sending and compute the game stuff.
There must be a ready made open source server floating on around somewhere, you just need to look hard for it. But since you have already achieved a lot, good luck.
No, I haven't as such any practical experience with server development, just a bit of knowledge about servers here and there.
> Isnt it bad having like 1000 threads opened at same time?
Its better than having 1000 processes running at the same time. Clients have to be serviced -- threads or processes, take your pick. And believe me, they don't call threads lightweight processes for no reason.
> I dint tell much about the server... it ll be a game server, basicly accepting conections, receveing data, sending and compute the game stuff.
There must be a ready made open source server floating on around somewhere, you just need to look hard for it. But since you have already achieved a lot, good luck.
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Justification
- Next Thread: problem in using isnan()
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






