On Thursday, November 7, 2002, at 08:52  PM, Andrew Piskorski wrote:

On Thu, Nov 07, 2002 at 08:06:37PM -0500, Gabriel Ricard wrote:
Speaking from the point of view of a recent convert from the
Apache/PHP
world, one thing that will really lower the bar for people like me is
a
document (or article) along the lines of "AOLServer and Tcl for
Apache/PHP users." From the end user stand point it may be good to
have
As a real live recent convert, what led you convert?  And what is
better/worse about AOLserver/Tcl vs. Apache/PHP?  I'm personally
curious, but maybe your answers would also be an effective
evangelization document!
Curiosity mainly. I work on a fairly large web application at the
office, and I've been researching ways to expand it and ensure its
maintainability in the future. I've been looking into as many different
options as possible for implementing a new version of the application.
PHP is ok, but I wanted to know what my options were. I've looked at
and played with python, ruby, even lisp (after reading about how yahoo!
stores was created/bought). PHP is nice, but it doesn't really seem to
scale that well past a single server, and I'm looking for reliability
as well as performance, so multiple webservers sitting behind a load
balancer seems like the best option. For a few months I spent time
playing with SRM, an application server for PHP. It's a great idea, but
it's not near production quality yet, and work on it is slow.

At some point I ran across Philip Greenspun's book. I think that was
mostly related to hearing about what happened to ArsDigita (damn VCs).
So, I read his book a few times, and absorbed as much else as I could.
At some point I figured I'd give AOLServer a try. I wanted to try PHP
with it as well.

I have to admit, when I first started playing with AOLServer I was
quite dumbfounded. But, after spending a week or so reading as much as
I could about it and Tcl and going to B&N and reading through some
books there it seemed rather ok. I've got a growing list of the things
I think make AOLServer/Tcl great:

- AOLServer is multi-threaded. Uses less resources than Apache, and is
considerably more reliable. (Yes, Apache 2 is multi-threaded, and PHP
is thread-safe, but there are still issues with using the two together
and they are not guaranteed to be reliable for production use)

- AOLServer's configuration is considerably easier to understand (at
least for me). Now that I've taught myself Tcl, reading through the
config file is a breeze. Everything makes sense. I can easily locate
where certain configuration parts are. In Apache, PHP's configuration
is usually three different commands in three completely separate
locations (LoadModule, AddModule, and then AddTypes to handle PHP).

- DB connection pooling. Apache is great for running multiple websites,
but for running a single web application, AOLServer, frankly, is the
shit. Yes, in Apache and PHP there are persistent connections, but how
useful is that when they're only available per pre-forked process? It
doesn't save as much time as having a single pool of database
connections open and ready anytime.

- I absolutely *LOVE* the control over URL mapping in AOLserver. So far
as I know, there's no way in Apache to say "take any requests for
/cmd/* and process them with this PHP function"

- I like the idea of moving the authentication out of the scripts
themselves and into a tcl init script that sets up a bunch of filters.
Less work for the actual scripts to perform, and easier to maintain.

- ADP templating facilities are great. I love being able to create my
own tags and controlling how that tag is processed. That's just not
available in PHP unless you use Smarty (I don't know if it allows for
custom tags) or write it yourself.

       - Note: my only gripe with ADP is that the following does not appear
to work:

               if { [check $something] == 1 } {
                       %>
               <b>break out of Tcl mode and process some HTML conditionally</b>
                       <%
               }

               In PHP that is perfectly possible.

- Another big bonus for AOLServer/Tcl is the preloading of code
libraries in your server/tcl directory. The closest PHP gets to this is
caching systems like APC and Zend Accelerator. Having all of your
utility code available instantly so it doesn't have to be parsed and
processed for each request.

- the built-in cron-like task scheduling system is great too. makes it
a lot easier to maintain your app when all of its functionality is in
one place. if only there was an MTA system that tied in with AOLServer
too... (is there??)

- stability / reliability. in benchmarking AOLServer and Apache on my
mac at the office, I found that Apache had some reliability issues. out
of 50,000 requests Apache would have about 1,000 failures. AOLServer,
on the other hand, had about 2-6. Also, when I hit Apache really hard
(50 concurrent users or more), it would soak up all availble CPU so my
system's load was at 150!. AOLServer never made the load go higher than
5, and used about 80% CPU.


packaged versions of AOLServer with snazzy front-ends for
configuration
and maintenance/status of the server. I'm not a terrific write, but I
"snazzy configuration front-ends", yuck!  Well, that was my first
reaction anyway.  If someone really wants to do this, making AOLserver
Tcl or ADP pages for controlling AOLserver should be the right way to
go.  One button out-of-the box install of useful applications sounds
potentially good though.
That's a good idea, I feel kinda silly not having thought about that at
all.
The only big problem with that is managing the configuration file
though. Well, I guess it's not a huge problem, but if the user were to
change the port / ip address it needs to write out a new config file
and restart the server.


I think the only thing I'm still hung up on is arrays. In PHP it was
ultra-easy to handle database rows using associative arrays,, and
handling large numbers of rows in multi-dimensional arrays. I don't
really know how to emulate that in Tcl, without setting up a separate
API to handle it. Anyone have some tips on that?
I know nothing about PHP's arrays, but it sounds like you're running
They're just hash tables, and they can contain anything. (string, int,
float, another array, object, etc.)

into the fact that unlike lists, which may contain other lists, Tcl
arrays can't contain other Tcl arrays, they can only contain named
references to other Tcl arrays.  I know there's been talk in the past
about changing that limitation, but I don't know whether it's
currently on the Tcl core team's agenda, or what they think about it.
What is a named reference to an array?

In Tcl, if I wanted to get all the rows at once and store them in some
structure, I'd probably use either db_list_of_lists:

  http://openacs.org/api-doc/proc-view?proc=db_list_of_lists
Yeah, that's one of the things I thought I'd have to do. My only issue
with it is dealing with the data in the list based on a numerical
index. I guess I'm just spoiled by the associative arrays in PHP.

or one of the related OpenACS db or templating procs.  Or, I might
store each row as a list in a Tcl array - as long as you include a
column with a unique id in the list, that works fine.

To store multiple rows each of multiple columns directly in a Tcl
array (without any embedded list structures), you just need to embed
more info into the Tcl array keys.  I've never done that myself, but
it would work, something like what the "A simple database" page on the
Wiki shows:

  http://mini.net/tcl/1598.html
Another possibility, but it makes it more of a pain to get extra data
out of the array like a list of all of the keys for the array.

- Gabriel

Reply via email to