From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.devel Subject: Re: Non-blocking web server Date: Mon, 25 Mar 2024 17:24:55 +0800 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000ec1a79061478bfbf" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7450"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-devel To: Ryan Raymond Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Mon Mar 25 10:25:59 2024 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rogac-0001gg-DF for guile-devel@m.gmane-mx.org; Mon, 25 Mar 2024 10:25:58 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rogZz-0003Lw-8X; Mon, 25 Mar 2024 05:25:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rogZw-0003Ky-QV for guile-devel@gnu.org; Mon, 25 Mar 2024 05:25:17 -0400 Original-Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rogZr-0004PP-R3 for guile-devel@gnu.org; Mon, 25 Mar 2024 05:25:16 -0400 Original-Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-56c197d042fso330733a12.0 for ; Mon, 25 Mar 2024 02:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711358709; x=1711963509; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DXWXn/LR4KUtDWlLRx8HNQWseywWAflbfYcnx+UWEKQ=; b=f68J1EqyodbaiLcO+JFWUUR7t1U4Kjm/MYLueTPRmvRZYAJ/uUYYPchps2VW6Ig44J YSslZrqmWAaJKORWp3PAZpIMeqanfg0EXIFAZXAugw5bZBnAJLcXTdEJE+cFDDvl73p9 l0EgMxKFsgEbb6ySotCQGMWbNyAT196wPvXFT+OLxDmIpOMzW92kZYfVWJpBTuLXdd8M oN8WjupLB/RX3yZbeHXLEuDLIaIvIDElH+P4WOLlIFoc4cPq5T0Iy/fwaXt6qUm4WSDq QLAQtdomc4xk3To7PesQDEMjb0mGksCGvjW0Z4ebHY+CnLI1N4JGlMXACFw0sv5oB6kM +TPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711358709; x=1711963509; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DXWXn/LR4KUtDWlLRx8HNQWseywWAflbfYcnx+UWEKQ=; b=bv8F8PTjSdZo4n4PK5huCjUIMffv4AMSohhzJ7UYtV+HRKw0o0R1uHlA5XlnQzLdAg IoEhQoO6wVzO8E5T1uHYbDkjjIvro7GuJmwCK7luh4ovulRmrXe3vCK+UZQv7dxO0csB MQxFMifLjBf9+75+t2OXBglTLeiHWmmlOwtIVSpY/aKMItz3lVnl1t+OzWI3y9VSkZgH AzRX3e60yq+vwvUX7F4MdE/6Qjb+1cQbQx8aRWcom43FaJNJx1bJ5U9HP0irwOPs7s5P 2eFY4s2mw3PrtZ0VVufT6533GOjQfA0dUPDxabQb8x4h/LqQvPd7UdxRarmXCdjTxOaX 4WSQ== X-Gm-Message-State: AOJu0Yza5yTDoTvPBMGyqGzFF+Z1Qu8FTBaMVrQpjwf9whngvrBDAqfV PSnsVSMb4dX6wac6bWg0JwzgQ++g76X6GxSXHPhW0pVyuCHJa+0k4V8/WA4RDc3msoUuHiGOb24 ds4EYwX6ZY0qiGbu4vP12aCCRPb8q9cpcPK8= X-Google-Smtp-Source: AGHT+IHfBoRSk+ONcdSPzSze+nFL1hGN1rrEImQk97PSXKEHVNe7R1J254xMcGv4Rs8au5D5qRLQXuggWEVmMSbEL74= X-Received: by 2002:a17:907:7788:b0:a46:9e84:37d7 with SMTP id ky8-20020a170907778800b00a469e8437d7mr3924709ejc.74.1711358708813; Mon, 25 Mar 2024 02:25:08 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=nalaginrut@gmail.com; helo=mail-ed1-x52c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22370 Archived-At: --000000000000ec1a79061478bfbf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=AFAM Ryan Raymond 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 > --000000000000ec1a79061478bfbf Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Ryan!
For the single-threade= d 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 you= r own scheduler

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

Of course y= ou may enhance it with thread pool.


Best=C2=A0regards.

<= br>
--000000000000ec1a79061478bfbf--