libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] MHD threading models: what model is similar to Least


From: silvioprog
Subject: Re: [libmicrohttpd] MHD threading models: what model is similar to Least Connected?
Date: Mon, 5 Dec 2016 14:46:16 -0300

Master,

I'm going to test it in C simulating my scenario (in Pascal), the idea using a list of daemons is really awesome.

Thanks a lot for the full example, I probably will be back with some news! :-)

On Fri, Dec 2, 2016 at 4:40 PM, Evgeny Grin <address@hidden> wrote:
You will need something like:

-----------------
  size_t N = 0; /* number of inited daemons */
  size_t n = 0; /* current worker */
  MHD_Daemon* daemons[MAX_DAEMONS];
  daemons[N++] = MHD_start_daemon (MHD_USE_NO_LISTEN_SOCKET |
MHD_USE_SELECT_INTERNALLY, ....);
  while (processingAllowed())
  {
    int fd = accept (listen_fd, &addr, &addrlen);
    if (-1 == fd)
      continue;

    if (!isSomeFunctionOfMyAppResponding())
    {
      if (N < MAX_DAEMONS)
      { /* Add new daemon if space is available */
        daemons[N++] = MHD_start_daemon (MHD_USE_NO_LISTEN_SOCKET |
MHD_USE_SELECT_INTERNALLY, ....);
      }
      n++; /* Switch to next worker */
      if (MAX_DAEMONS == n)
      {
        n = 0; /* Return processing to first daemon */
      }
    }
    MHD_add_connection (daemons[n], fd, &addr, &addrlen);
  }
-----------------

"Slow" daemons will continue processing their connections, when slowdown
is detected, you will switch new connections to next daemon.

--
Best Wishes,
Evgeny Grin

--
Silvio Clécio

reply via email to

[Prev in Thread] Current Thread [Next in Thread]