943,776 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 9401
  • C++ RSS
May 14th, 2007
0

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

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MarcosEdu is offline Offline
4 posts
since May 2007
May 14th, 2007
0

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

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
May 14th, 2007
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MarcosEdu is offline Offline
4 posts
since May 2007
May 14th, 2007
0

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

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
May 14th, 2007
0

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

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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
May 14th, 2007
0

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

Click to Expand / Collapse  Quote originally posted by ~s.o.s~ ...
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 =)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MarcosEdu is offline Offline
4 posts
since May 2007
May 14th, 2007
0

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

> 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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
May 14th, 2007
0

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

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 =)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MarcosEdu is offline Offline
4 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Justification
Next Thread in C++ Forum Timeline: problem in using isnan()





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC