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 think a web server would be better coded in another language -- probably php or even C#, which are designed for that sort of stuff.

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=)

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.

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.

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 =)

> 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.

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 =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.