[Ur] Strategy - UrWeb Backend

Marc Weber marco-oweber at gmx.de
Tue Dec 7 20:00:44 EST 2010


Excerpts from Adam Chlipala's message of Wed Dec 08 01:03:42 +0100 2010:
> I find it hard to believe that it doesn't matter if a web application 
> server uses several times more memory than it needs to, but maybe we 
> really have come to live in a world that crazy. ;)

  Yes - we do. Imagine a server running PHP. Imagine each query to take
  100ms (which is the average time it takes PHP servers to server pages
  which have been written minimizing dev time).
  Now imagine that each customer visits about 20 pages each day. Let's
  assume you have only one "rush hour per day".
  This still means that you can serve:

  60min * 60sec/min * 10 pages/sec / 20 (pages/customer)  = 1800 customers !

  And if you have 18000 customers within one hour .. then you're lucky.

  And if you had that much customers you could start thinking about how
  to upgrade your system without interruption.

  Then you wait 6month and your computers have 8 times more cores - and
  it will be able to server 1800 * 8 requests each hour. I know scaling
  does not happen in a linear manner. You get the point - don't you?

  So if you write facebook it matters. But they pay a team of 20 people
  or so anyway. They compile their PHP though - for speed reasons.

  The reasons I'm interested in urweb is that it can catch many types of
  errors at compilation time. Its not because of its speed or memory
  consumption.

> > Benefits of JS target:
> >   - never think about memory
> Can you expand on this point?  It sounds surprising.
I meant: Never think about when to free memory. If the languages takes
care about it you don't have to.

Compare your code uw_global_set, uw_global_get
with Ruby code:

  RUBY:

      @h = Hash.new
      def get(key)
        @h[key]
      end
      def set(key, value, free)
        @h[key][1].call() if @h.has?[key]
        @h[key] = [value, free]
      end

      (note: maybe you can get rid of

  C code doing the same:
  
        void *uw_get_global(uw_context ctx, char *name) {
          int i;

          for (i = 0; i < ctx->n_globals; ++i)
            if (!strcmp(name, ctx->globals[i].name))
              return ctx->globals[i].data;

          return NULL;
        }

        size_t uw_globals_max = SIZE_MAX;

        void uw_set_global(uw_context ctx, char *name, void *data, void (*free)(void*)) {
          int i;

          for (i = 0; i < ctx->n_globals; ++i)
            if (!strcmp(name, ctx->globals[i].name)) {
              if (ctx->globals[i].free)
                ctx->globals[i].free(ctx->globals[i].data);
              ctx->globals[i].data = data;
              ctx->globals[i].free = free;
              return;
            }

          if (ctx->n_globals+1 > uw_globals_max)
            uw_error(ctx, FATAL, "Exceeded limit on number of globals");

          ++ctx->n_globals;
          ctx->globals = realloc(ctx->globals, ctx->n_globals * sizeof(global));
          ctx->globals[ctx->n_globals-1].name = name;
          ctx->globals[ctx->n_globals-1].data = data;
          ctx->globals[ctx->n_globals-1].free = free;
        }

        Now ask a programmer how many ways there are to do something
        wrong.. :)

        Worse: No way to reuse your code other than doing copy paste.

I've read a very interesting statement once which said: The linux kernel
probably has less bugs than the windows one. Why? The amount of bugs per
line is probably the same - but the linux kernel has less lines.

Its not about C - its about the amount of lines. The JS interpreters
also provide stack traces - so if something goes wrong there are chances
that you can find out why fast.

Now you know why writing JS or Ruby extensions wins easily compared to
writing C FFI extensions - because you don't have to code up simple
lists or hashes over and over again.


After fixing the realloc issue I'm happy - because I can use Ruby then -
and ask others to recode interfacing code using C if - and only if - my
projects take off. Some hours of my time are probably a much bigger
waste of resources than letting a v-server run for several days.


Note that I ddin't talk about coding the core code of an application
(Ur) I only talked about adding some missing pieces using FFI.

Marc Weber



More information about the Ur mailing list