View Single Post
Old Jul 29th, 2004, 10:09 PM   #6
unknowen
Newbie
 
Join Date: Jun 2004
Posts: 11
Rep Power: 0 unknowen is on a distinguished road
Sorry for not answering directly, different time zone.

Will try to explain what I want to do and how.

A little bit of background, I have about 5 years of C/C++ experience all of them used VC++, some time ago at home started to play with Linux, so have to get into new things. And sometimes answer right at your nose, but you don't see it because of windows thinking.

First of all let’s start with kernel, 2. 4 has slow scheduler, but I need fast threading program, so I tested some code pieces with 2.6.7 and performance with POSIX threads are better, of course I understand that I don't need to care about kernel, just want to use fastest one for my MEGA server

Second. Basically I have server to many clients, but clients have to interact with some date. So fork will not work (ok will fork but then I have to manage shared memory - don't want to). I wrote server that works one thread per client using blocking sockets, but after reading some info about Linux this is definitely not the best idea if client number is large.
Switched to one thread listens to all clients that are connected to non blocking socket. Logics works fine for that, except thread who is listening for incoming data, that thread takes al CPU .

At this point I stopped and posted not correctly described question, again sorry.

After reading I found that Linux has function clone (), that works the same way as fork () except this function is working in the same memory space, BUT not portable.

And the answer is function select (), (of course there are others like pool etc), so right now I will write something like this.

1) Thread accepting connections
2) Waiting in select () function on data arrive reads data and posts in worker queue
3) On data arrived worker thread wakes up do some thing and gets some sleep .

HUH long, but will write more.

I'm thinking about other stuff. I have calculated that client will send maximum 2 messages per second; I hope 1 thread should be enough to read them.

Second algorithm I thinking of is - Thread accepting connections and on each new ten clients creating thread that goes to select () function on data arrive process all data, and wait for next data.

Here I see some more jobs, because I have to control disconnecting client count, so I don't get situation that in some cases thread is working for one client only.

Any ideas or comments are welcome.
If someone wants I can tray to explain more detailed what I'm going to write and put some code pieces as well.

P.S. I'm not a native speaking English, so sorry for my mistakes
unknowen is offline   Reply With Quote