English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
scalable web apps
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-07-25 (22:24)
From: Dario Teixeira <darioteixeira@y...>
Subject: Re: [Caml-list] scalable web apps

> How does Ocsigen handle database operations?
> I assume they need to be asynchronous because of
> lightweight threads (Lwt).

Ocsigen itself is agnostic on DB matters.  However, your assumption
concerning the Lwt-friendliness of the DB layer is correct.  There's
basically two solutions to this problem: 1) Use whatever DB bindings
you prefer, but wrap them under Lwt_preemptive; 2) Use Lwt-aware DB
bindings.  For the latter the usual recommendation is PG'OCaml [1],
which in its current incarnation can be used in a monadic fashion
(with Lwt, for example).  If you want to interact with the DB at
an even higher level there's also Macaque [2], which is part of
the Ocsigen project (note that Macaque relies on PG'OCaml for the
low-level work).

When using PG'OCaml with Lwt, pretty soon you'll come across the
problem of connection pooling.  This is the moment you'll want to
look into Lwt_pool, which makes this task a breeze.

Finally, if you're looking for a concrete example of all this stuff
put together I suggest taking a look at the Lambdium's database.ml
module [3] (you can find it under 'backend/src/data/').

Hope that's enough to get you going...
Dario Teixeira

[1] http://pgocaml.berlios.de/
[2] http://ocsigen.org/macaque/
[3] https://forge.ocamlcore.org/projects/lambdium/