unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Nala Ginrut <nalaginrut@gmail.com>
To: Ryan Raymond <rjraymond@oakland.edu>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: Non-blocking web server
Date: Mon, 25 Mar 2024 17:24:55 +0800	[thread overview]
Message-ID: <CAPjoZofbBAeC3jUCKUwRAdqTAHYYNa1p70TK-j1JU-UAQJXWGA@mail.gmail.com> (raw)
In-Reply-To: <CAGvJ-HQQZ++7g36ti_X2TB_1iMMDoL70CNzMstwZAu+QZ53tmQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1526 bytes --]

Hi Ryan!
For the single-threaded non-blocking server in Guile, you have to make sure
at least 3 steps:
1. set socket to non-blocking
2. enable suspended ports to prepare delimited-continuation powered
coroutine
3. designed your own scheduler

Even in the single thread, you can handle requests concurrently because of
the coroutine based on delimited-continuation.

Of course you may enhance it with thread pool.


Best regards.


On Mon, Mar 25, 2024 at 4:04 AM Ryan Raymond <rjraymond@oakland.edu> wrote:

> Hello, all.
> I was able to build a non-blocking web-server using network sockets.
> However, the existing guile web/server.scm implementation is
> single-threaded and therefore blocking, which is sub-optimal for some
> use-cases.
>
> I suggest we slightly modify the server logic to have an optional
> #:blocking? [bool] parameter which would enable behavior in line with the
> following excerpt from my own code. Obviously some changes would be made to
> methodology and code style, but you get the picture.
>
> (define (listen sock)
>   (let* (
>     (client-connection (accept sock))
>     (client-details (cdr client-connection))
>     (client (car client-connection)))
>     (begin-thread
>       (sigaction SIGPIPE SIG_IGN)
>       (handle client)
>       (close client))
>     ))
>
> This shouldn't cause any backwards-compatibility issues since it's
> optional, but the specifics of web/server.scm might cause problems.
> Let me know what you think!
> Ryan
>

[-- Attachment #2: Type: text/html, Size: 2143 bytes --]

  parent reply	other threads:[~2024-03-25  9:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-24 19:41 Non-blocking web server Ryan Raymond
2024-03-25  5:31 ` tomas
2024-03-25  9:24 ` Nala Ginrut [this message]
2024-03-25 10:44 ` Maxime Devos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPjoZofbBAeC3jUCKUwRAdqTAHYYNa1p70TK-j1JU-UAQJXWGA@mail.gmail.com \
    --to=nalaginrut@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=rjraymond@oakland.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).