Web related programming with mdisp

Vladimir Sekissov svg@REDACTED
Mon Mar 24 17:38:32 CET 2003


Good day,

Experimenting a lot with web related programming using mdisp and yaws
I've found that I could write my programs in two major styles:

1. Application consists from mdisp managed processes communicating
with mdisp.

Advantages:

It looks mostly like ordinary Erlang application

Disadvantages:

Big waste of resources especially in nondeterministic web interaction.
All processes must communicate only with mdisp to be manageable in
uniform way.
Process management must be implemented explicitly by application (no links).

2. Writing application in Distel-like trampoline style, where
application consists from custom threads and thread combinators.

Every thread accepts only one argument(Yaws #arg{}) and return:

{continue, Result, Continuation} | {die, Result}

Result is displayed to the user and application dies or continue with
Continuation waiting user response.

Combinators are threads themselves and manage other threads constructing
output stream.

For example simple combinator which sequentially runs
threads and calls next with result of previous as argument.
Every thread can interact with user returning
{continue, Result, Cont} arbitrary times, start subthreads etc...

applyn([F]) ->
  fun (Arg) ->
      F(Arg)
  end;
applyn([F|Fs]) ->
  Fun =
    fun (Arg) ->
	case F(Arg) of
	  {continue, Res, Cont} ->
	    continue(Res, applyn([Cont|Fs]));
	  {die, Res} ->
	    case Fs of
	      [] ->
		die(Res);
	      _ ->
		(applyn(Fs))(Res)
	    end
	end
    end.

Advantage:

Lower waste of resources and ability to save whole application state
on the user side if you want to switch from server-side store.

The major disadvantage:

not so natural programming style.


I'm slightly in troubles which approach to use as major and would be
glad to here your thoughts and suggestions.

Best Regards,
Vladimir Sekissov



More information about the erlang-questions mailing list