comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Reducing the size of executables produced by GNAT
Date: Wed, 13 Feb 2008 07:52:45 -0800 (PST)
Date: 2008-02-13T07:52:45-08:00	[thread overview]
Message-ID: <4b2cd4e1-c0dc-4cd5-9e3b-1c4955eb0f08@l16g2000hsh.googlegroups.com> (raw)
In-Reply-To: 40e9c01a-8d31-4554-9d9b-18cce7834d56@s12g2000prg.googlegroups.com

First here are a couple hints:

* compile with -Os (optimize for size)
* strip the executable maximally

Do not worry though that the machine executes 45 KB of instructions.
Part of the executable contains data, which you cannot reduce but
which is obviously not executable.

But this is all besides the point. Your real problem is CGI. If you
want performance, forget GCI. GCI is probably the worst way to do
dynamic web sites and has been deprecated for the past 10 years or so.
120K or 45K or 10K CGI executables won't make a difference because the
executable files will be in the buffer cache anyway. What does make
CGI slow is creating a new process with environment variables, file
descriptors, etc. and then the necessary inter-process communications
between the web server and the scripts. And CGI does that for each
incoming HTTP request: this is bad.

The proper way is to write one executable that embeds the web server
itself. The Ada Web Server library from AdaCore was designed
specifically for this purpose.  With AWS, your one executable will be
larger but much, much faster than CGI. And, since you will not launch
your application with each HTTP request but only once and leave it
running all the time, dynamic linking will be an option.

Your web application can be very simple. Start listening on port 80.
For each incoming request, call an Ada procedure that responds to the
request. Done.

Now, if your web application has many clients, you may want to be able
to service more than one request at a time. For this, use Ada tasking.
Your program first creates a queue of incoming requests, then a fixed
number of worker tasks. After the worker tasks are created, it starts
listening on port 80. For each incoming request, instead of processing
the request, it places it in the queue.  Each worker task is an
infinite loop that waits for a request to become available in the
queue, takes it, processes it, sends the response to the client, and
comes back.

In either case (single-task or multi-task) you have a fixed number of
tasks that are infinite loops waiting for user input. Thus you never
have to fork() a new process. This is good.

And, all of this is one single executable program.  If this program is
statically linked and contains, in its data segment, all images and
web page templates necessary, then it never has to read from the disk
at all, running entirely from memory. That's how you achieve
performance and small footprint.

Read the details in the AWS User's Guide.

--
Ludovic Brenta.



  parent reply	other threads:[~2008-02-13 15:52 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-13 11:52 Reducing the size of executables produced by GNAT Hibou57
2008-02-13 14:38 ` Martin Krischik
2008-02-13 20:03   ` Hibou57
2008-02-13 20:25     ` Pascal Obry
2008-02-13 21:41       ` Maciej Sobczak
2008-02-13 23:35         ` Ludovic Brenta
2008-02-13 20:37     ` tmoran
2008-02-14 10:12       ` Georg Bauhaus
2008-02-14 11:07         ` Ludovic Brenta
2008-02-14 22:07           ` Hibou57
2008-02-15  0:19             ` Robert A Duff
2008-02-13 21:27     ` Gautier
2008-02-13 22:14       ` Hibou57
2008-02-14 10:34         ` Georg Bauhaus
2008-02-14 10:53         ` anon
2008-02-15  5:52         ` Randy Brukardt
2008-02-15  5:52         ` Randy Brukardt
2008-02-15  5:52         ` Randy Brukardt
2008-02-19  0:41           ` Hibou57
2008-02-13 14:50 ` gautier_niouzes
2008-02-13 15:41   ` Pascal Obry
2008-02-13 15:52 ` Ludovic Brenta [this message]
2008-02-13 16:19 ` anon
2008-02-13 16:28   ` Pascal Obry
2008-02-13 17:34 ` Tero Koskinen
2008-02-13 21:32 ` Jeffrey R. Carter
2008-02-14  6:58 ` Jacob Sparre Andersen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox