C++ Server: Multi-thread VS Single-thread

Reply

Join Date: May 2007
Posts: 4
Reputation: MarcosEdu is an unknown quantity at this point 
Solved Threads: 0
MarcosEdu MarcosEdu is offline Offline
Newbie Poster

C++ Server: Multi-thread VS Single-thread

 
0
  #1
May 14th, 2007
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
Last edited by WolfPack; May 14th, 2007 at 7:18 pm. Reason: Removed the unnecessary bold formatting.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,149
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1435
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: C++ Server: Multi-thread VS Single-thread

 
0
  #2
May 14th, 2007
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.
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4
Reputation: MarcosEdu is an unknown quantity at this point 
Solved Threads: 0
MarcosEdu MarcosEdu is offline Offline
Newbie Poster

Re: C++ Server: Multi-thread VS Single-thread

 
0
  #3
May 14th, 2007
Originally Posted by Ancient Dragon View Post
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.
Tks for the reply

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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,149
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1435
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: C++ Server: Multi-thread VS Single-thread

 
0
  #4
May 14th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: C++ Server: Multi-thread VS Single-thread

 
0
  #5
May 14th, 2007
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.
Last edited by ~s.o.s~; May 14th, 2007 at 1:55 pm.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4
Reputation: MarcosEdu is an unknown quantity at this point 
Solved Threads: 0
MarcosEdu MarcosEdu is offline Offline
Newbie Poster

Re: C++ Server: Multi-thread VS Single-thread

 
0
  #6
May 14th, 2007
Originally Posted by ~s.o.s~ View Post
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.
Tks for the reply.

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 =)
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: C++ Server: Multi-thread VS Single-thread

 
0
  #7
May 14th, 2007
> 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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4
Reputation: MarcosEdu is an unknown quantity at this point 
Solved Threads: 0
MarcosEdu MarcosEdu is offline Offline
Newbie Poster

Re: C++ Server: Multi-thread VS Single-thread

 
0
  #8
May 14th, 2007
Yeah...

For sure i dont need many processes... just threads..

Now i ll have to decide between 3, 5 or 1000+ threads

Tks for the help =)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC