From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id BE0C3BC6B for ; Mon, 8 Oct 2007 18:04:55 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAM/xCUfAXQImh2dsb2JhbACBWYxqAgEICik X-IronPort-AV: E=Sophos;i="4.21,243,1188770400"; d="scan'208";a="2631853" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 08 Oct 2007 18:04:55 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l98G4qrC001728 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 8 Oct 2007 18:04:55 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAEbyCUfU4363nmdsb2JhbACBWYxqAgEBBwQGERg X-IronPort-AV: E=Sophos;i="4.21,243,1188770400"; d="scan'208";a="2450542" Received: from moutng.kundenserver.de ([212.227.126.183]) by mail1-smtp-roc.national.inria.fr with ESMTP; 08 Oct 2007 18:04:53 +0200 Received: from gate.lan.gerd-stolpmann.de (dslb-084-059-100-228.pools.arcor-ip.net [84.59.100.228]) by mrelayeu.kundenserver.de (node=mrelayeu2) with ESMTP (Nemesis) id 0MKwtQ-1Iev6A2dBg-0003Ab; Mon, 08 Oct 2007 18:04:51 +0200 Received: from flakew.lan.gerd-stolpmann.de (fw.lan.gerd-stolpmann.de [192.168.1.1]) by gate.lan.gerd-stolpmann.de (Postfix) with ESMTP id 4FB3FC0C6; Mon, 8 Oct 2007 18:04:50 +0200 (CEST) Subject: Re: [Caml-list] Correct way of programming a CGI script From: Gerd Stolpmann To: Tom Cc: Caml-list List In-Reply-To: References: Content-Type: text/plain Date: Mon, 08 Oct 2007 18:04:49 +0200 Message-Id: <1191859489.10162.16.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Provags-ID: V01U2FsdGVkX1/pwdY4baeJIU5DhLCirGjkb3mDVmnqmCs8PRu 31v1R1u36WY6NolB6AK+alkgtcgGWhBUsA7dtPtm8IzYb+oB58 rofmNLFWkoxctySdcY7l9wWOde15MqJ X-Miltered: at discorde with ID 470A5524.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; gerd:01 stolpmann:01 caching:01 ocaml:01 ocaml:01 buffer:01 buffer:01 ocamlnet:01 ocamlnet:01 scalable:01 netcgi:01 gerd:01 stolpmann:01 viktoriastr:01 64293:01 Am Montag, den 08.10.2007, 17:08 +0200 schrieb Tom: > Hi! I am in a process of making a website (which might receive > substantial amounts of traffic), and am considering options for the > backend. I discarded PHP and other similar server-side scripting > languages, due to performance problems (I suspect that PHP and similar > could not scale well, unless I implemented complex caching > techniques). I plan to use OCaml to generate static .html documents > from the content from the database. Since the content will probably > change not as often as it will be accessed, I believe this is the > better way (as opposed to accessing the database every time a user > wants to load the page). > > So, OCaml programs will only be run seldomly to access the database > and generate HTML files, using the data fetched from the DB. However, > I am still worried whether this would cause too much performance > impact. > > I heard that OCaml is particularly slow (and probably > memory-inefficient) when it comes to string manipulation. What is the > preferred way in handling strings (building long strings from short > parts - something StringBuilder would be used in Java)? Does anybody > have any experience concerning this kind of applications? No, this is nonsense. Of course, you can slow everything down by using strings in an inappropriate way, like let rec concat_list l = match l with [] -> "" | s :: l' -> s ^ concat_list l' Use the Buffer module instead: let concat_list l = let b = Buffer.create 243 in let rec concat l = [] -> () | s :: l' -> Buffer.add_string b s; concat l' in concat l; Buffer.contents b > > What about the startup time and memory usage of the program? Could > these affect the stability and efficiency of the web server? > > (Hope someone will be able to decipher my language and care to > answer :P ) Have a look at ocamlnet (ocamlnet.sf.net). It has plenty of ways of building web apps. For example, you can easily run your own HTTP server in a multi-processing or multi-threading setup. Or you can connect your web app with Apache by using fastcgi or a few other available protocols. All this is pretty much scalable. There is no support for generating HTML, however. An example for a stand-alone webserver (it is accompanied only by a config file): https://godirepo.camlcity.org/wwwsvn/trunk/code/examples/nethttpd/netplex.ml?rev=1122&root=lib-ocamlnet2&view=auto Here is the same for the "connect to Apache" approach: https://godirepo.camlcity.org/wwwsvn/trunk/code/examples/cgi/netcgi2-plex/?root=lib-ocamlnet2 In either way, it is possible to keep the connection to the db in case you need it for generating the page. Hope this helps, Gerd -- ------------------------------------------------------------ Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de Phone: +49-6151-153855 Fax: +49-6151-997714 ------------------------------------------------------------