Re: Structure of the multitasking server
- From: anon@xxxxxxxx (anon)
- Date: Mon, 22 Sep 2008 02:32:11 GMT
Why use "GNAT.Sockets.Check_Selection"?
Well, in TCP/IP system the designers of TCP/IP created a routine called
TCP/IP "Select", that is designed to allow the use of multi-servers or
multitasking type of servers within one environment. There are reasons
that goes beyond Ada and other languages that states why a multi server
design should use the TCP/IP "Select" routine instead of multi tasks where
each task uses a TCP/IP "Accept" statements to block the server routine
until a call or a connection is made, basically it has to do with limited
system resources.
Note: TCP/IP "Accept" can only monitor one connection port while the
TCP/IP "Select" allows monitoring up to 32 at one time in one routine.
which makes the TCP/IP "Select" a better utilization of system resources.
Now, in GNAT the TCP/IP "Select" routine is ported to Ada by the function
"GNAT.Sockets.Thin.C_Select" which is the low-level C and non-portable
version of the routine. The non-portable TCP/IP "Select" is wrapped into
a procedure called "GNAT.Sockets.Check_Selection" that is more portable.
Why only 27 servers per TCP/IP "Select" routine Well, the designers created
the TCP/IP "Select" to use 3 32-bit word to detect or flag, up to 32 servers
(bitmapped). Now, the TCP/IP system uses the first 3 file descriptors mapped
onto the first 3 sockets positions and are defined as the standard system I/O
(Stdin (0), Stdout (1), Stderr (2)) which is hard coded in the TCP/IP "Select"
routine. And the designer of the "GNAT.Sockets" uses two additional random
assigned sockets or file descriptors (depends on port/version of GNAT) to build
the Selector type for interfacing with the TCP/IP "Select" routine. So,
27 (User Allowed sockets) :=
32 (total sockets) - 3 (System defined) - 2 (GNAT RTL used)
Note: For Full documentation on why 32 sockets you will need to check
with the history of TCP/IP for the full story, but I would guess it
was because of limited resources back then. Most servers back then only
handle a few services, and that has not changed too much in todays world.
Today, only, the volume of clients has increased.
Plus, some system may have 1024 file descriptors, but the OS normally
limit the number of assigned/open file descriptors to 32 or less. And
that includes the 3 Standard I/O files.
-- TCP/IP Server Designed (GNAT)
Now, the best and "Tried and True" design for a multiple service server
is for a single batch designed monitor task with multi-service server task.
The monitor task setup and monitor 2 to 27 sockets. Then activate the
service server task, afterwards quickly reset and monitors/idles until
the next request is made. Simple and straight foreword design.
Why Best design: Uses less resources including CPU cycles. Which allow
the server tasks and other programs a timely access to their resource needs.
--
-- A simple outline for a multiple services type of TCP/IP server task
--
Server_Controller_Task:
Server_Number : Natural ; -- Set to maximum number of server task
-- value ranges 5..32 (27) ;
-- Initialize Controller variables
for Server_task_count in 5..Server_Number loop
idle until called ( Ada "Accept" statement ) ( socket )
map socket to the Signalling_Fds (read/write/exception)
end loop
-- Monitoring Routine: idle until a server is needed.
loop
setup or reset Selector variables -- required for every call
call Check_Selector function -- Idle until connected
Using returned Signalling_Fds, find and call the server task to handle job
end loop
exception
shutdown server in case of TCP/IP system exception. Or
Storage_Error, Program_Error, etc.
--
-- Each "Server_Service_Task" handles one type of service.
--
Server_Service_Task: 5..MAX(32):
-- Initialize: Inform controller task that server exist
-- and is ready to handle request.
Create Socket
Bind Socket to port and address
-- This call assign and map Socket to Signalling_Fds value
-- which allows the controller server to monitor the
-- connection request and active this server when needed.
Call controller_task ( Socket )
-- idle task until called. Then handle request.
loop
Set server resources to idle
idle until called to handle server job. ( Ada "Accept" statement )
Open Channel
Handle server service job
Close Channel
exception
handle lost of connection. Reset for next call
end loop
exception
handle Socket_Error in case of TCP/IP Socket exception.
shutdown server in case of TCP/IP system exception. Or
Storage_Error, Program_Error, etc.
In <2cfc647a-c9cb-4e0c-9909-7923575fd1ec@xxxxxxxxxxxxxxxxxxxxxxxxxxx>, Maciej Sobczak <see.my.homepage@xxxxxxxxx> writes:
On 20 Wrz, 01:01, a...@xxxxxxxx (anon) wrote:
Since you are using Channels, I am assuming that your talking about TCP/I=P
servers.
Not necessarily, although in this case it is indeed true.
In this case you should look into using the Check_Selector
Why? If I want to keep the number of pipelines relatively small, then
fixed pool of tasks seems to be quite clean.
Now the way GNAT has written the Selector function and the way the C_Sele=ct
is written the maximum number of server per Check_Selector is 27.
Is it documented somewhere?
The only "documentation" I have found is the .ads file for
GNAT.Sockets, and this detail is not mentioned there.
Also, on my system the default limit on the number of file descriptors
used with select(2) is 1024.
=A0That is,
each C_Select function can only monitor 32 sockets
What is C_Select? Why would it be more limited than select(2) (the
system-level one)?
--
Maciej Sobczak * www.msobczak.com * www.inspirel.com
Database Access Library for Ada: www.inspirel.com/soci-ada
.
- Follow-Ups:
- Re: Structure of the multitasking server
- From: Maciej Sobczak
- Re: Structure of the multitasking server
- References:
- Structure of the multitasking server
- From: Maciej Sobczak
- Re: Structure of the multitasking server
- From: Maciej Sobczak
- Structure of the multitasking server
- Prev by Date: Re: Structure of the multitasking server
- Next by Date: Re: Structure of the multitasking server
- Previous by thread: Re: Structure of the multitasking server
- Next by thread: Re: Structure of the multitasking server
- Index(es):
Relevant Pages
|