Re: Structure of the multitasking server




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

.



Relevant Pages

  • RE: TCP/IP Services Application encountered a problem and needed to close.
    ... I understand that you get error "TCP/IP ... Services Application encountered a problem and needed to close" on your SBS ... maybe the TCP/IP stack in your SBS server is ... I suggest you use netsh int ip reset command to reset the TCP/IP stack: ...
    (microsoft.public.windows.server.sbs)
  • Performanceproblem NW4.11 Client-Tausch Win9x auf XP
    ... NWClient incl. ... Protokolle IPX und TCP/IP laufen parallel; ... Am Server ...
    (de.comp.sys.novell)
  • Re: Please Help! Newbie VPN Problem...
    ... I've gone to the DHCP relay Agent in the "Routing and Remote Access" Panel under "IP Routing" and told it to send messages to the 192.168.1.1 address, which is where our router is. ... Ensure that the TCP/IP protocol is installed on your RAS server and that the TCP/IP protocol is selected in the Server Settings of the Network Configuration option of the Remote Access Setup dialog. ...
    (microsoft.public.win2000.ras_routing)
  • Re: Cannot Log on to SBS2003 with Win9x clients tho DHCP leases IP
    ... that netbios over TCP/IP is enabled. ... Can you post the ipconfig/all from a client? ... > Please note the ping failure from the server to the client. ... > Connection-specific DNS Suffix. ...
    (microsoft.public.windows.server.sbs)
  • Re: XP client cannot locate domain controller
    ... your computers tcp/ip properties. ... to be your DNS server. ... ipconfig /all command on each and the results will look similar to below. ... is that the time/day/date is correct on your laptop and that it is using ...
    (microsoft.public.windowsxp.network_web)