From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b59b337045eece60 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!wn11feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Structure of the multitasking server Reply-To: no to spamers (No@email.given.org) References: <8b4d1170-22e6-40d3-8ed1-096dc0163491@m36g2000hse.googlegroups.com> <2cfc647a-c9cb-4e0c-9909-7923575fd1ec@d1g2000hsg.googlegroups.com> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Mon, 22 Sep 2008 02:32:11 GMT NNTP-Posting-Host: 12.65.222.187 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1222050731 12.65.222.187 (Mon, 22 Sep 2008 02:32:11 GMT) NNTP-Posting-Date: Mon, 22 Sep 2008 02:32:11 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:2059 Date: 2008-09-22T02:32:11+00:00 List-Id: 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@d1g2000hsg.googlegroups.com>, Maciej Sobczak writes: >On 20 Wrz, 01:01, a...@anon.org (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