Previous Up Next

7  Conclusion and Perspectives

We have described, implemented, and evaluated several ways to implement light weight concurrency in OCaml. The complete code for the implementations is available on the web (http://christophe.deleuze.free.fr/lwc/). A direct style implementation involves capturing continuations, which is relatively costly (although much less than what is incurred by VM or system threads). Indirect style implementations perform better but force the programmer to write in a specific style.

As we saw, event-based programming can be seen as a form of trampolined style programming with an event-based scheduling strategy. We didn’t realize this immediately since event-based programming is mostly associated with imperative languages while trampolined style is with functional ones.

Apart from equeue that is not designed for massive concurrency, the light weight implementations can easily handle millions of threads. The trampolined implementation is the lighter, with the continuation monad slightly above. Using promises is significantly more costly: each cooperation point involves much more operations. Of course our examples are minimal, threads do very little work between cooperation points so any difference in the performance of their implementation is magnified. This should be kept in mind when looking at the performance results.

Our implementations are skeletons, realistic libraries should at least deal properly with I/O and exceptions. As we said Lwt is such a mature library based on the promise monad. We are currently developping a library (called µthreads) for light weight concurrency in OCaml, based on the trampoline scheme. More realistic applications, such as an FTP server and a DNS resolver, are also being developed.


Previous Up Next