From: Mark H Weaver <mhw@netris.org>
To: Nala Ginrut <nalaginrut@gmail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: [PATCH] Add current-suspendable-io-status parameter
Date: Tue, 14 May 2019 16:22:09 -0400 [thread overview]
Message-ID: <878sv8kcqb.fsf@netris.org> (raw)
In-Reply-To: <CAPjoZofSHzpvWnkC0Y8x=Sa-060XFTYZbWu90SzJuNPoVQ200A@mail.gmail.com> (Nala Ginrut's message of "Tue, 14 May 2019 12:22:24 +0800")
Hi Nala,
Nala Ginrut <nalaginrut@gmail.com> writes:
> On Tue, May 14, 2019 at 7:01 AM Mark H Weaver <mhw@netris.org> wrote:
>> I guess what you want is the ability to see incremental reports on the
>> progress of your large I/O operations. Is that right? If we are going
>> to add an API for this, it needs to be reliable, and always give reports
>> in terms of the high-level requests that the user gave.
>
> Yes, that's exactly what I want. We need to get the progress of I/O
> operation when it's blocking
> so that we can compute a fair priority for the tasks.
>
>> My preferred approach would be something like this: we could add a
>> 'put-bytevector-some' I/O primitive which writes some bytes from a
>> bytevector, blocking only as needed to write at least one byte. It
>> would return the number of bytes written. This can be used to implement
>> an efficient variant of 'put-bytevector' that gives you access to the
>> real-time progress information.
>
> I'm not sure if put-bytevector-some does the work, I'll list my concerns:
>
> 1. All I/O will be managed by Guile when we enabled suspendable-port.
> That is to say, from the users side, users never know their I/O
> operations are blocking or not. It's transparent to users.
> Guile will guarantee the I/O operations to be finished by managing all
> the blocking I/O mechanisms.
> Users can only interact with the task with read or write waiter, which
> are registered by users themselves.
> In this scenario, users are out of control of I/O operations. And they
> have no way to get the progress of I/O, since there's
> no way to pass this status to the waiter function except for
> parameters in my patch.
>
> 2. suspendable-port module has already provided a bunch of overridden
> bytevector-* functions.
> However, they're hidden from users. I think it's good since the
> purpose of suspendable-port is to abstract all these details from
> users. Users only consider the read-waiter and write-waiter for scheduling.
> If we provide the low-level bytevector functions to users to let them
> do the non-blocking I/O by themselves, just like most C framework
> does. Then Guile suspendable-port will lose a critical feature,
> although users can still implement asynchronous non-blocking I/O by
> themselves with a non-managed approach. Say, do the I/O, check result
> by themselves, and do the scheduling.
> Personally, I'm fine with this way, since I'm familiar with both ways.
> But managed I/O of suspendable-port is a good selling point for many
> inexperienced server-side developers, they can use it in Scheme just
> like IOCP or AIO.
>
> Of course, I may misunderstand your mind.
> Could you elaborate more about your approach?
Here's what I had in mind. I'm not suggesting that you use asynchronous
non-blocking I/O. 'put-bytevector-some' would be like 'put-bytevector'
except that it can write less than you asked it to. Ideally it would
block only as needed to write at least one byte. It would be analogous
to POSIX write(2).
Here's an untested draft implementation of 'put-bytevector*' which sets
the parameter 'current-io-status' to provide the information you wanted,
except that here the information will reliably refer to your own buffer.
The primitive it is built on 'put-bytevector-some' does not yet exist,
but we could add it. Note that 'put-bytevector-some' would still block,
and it would be suspendable.
--8<---------------cut here---------------start------------->8---
(define* (put-bytevector* port bv
#:optional
(start 0)
(count (bytevector-length bv)))
(let loop ((start start) (count count))
(unless (zero? count)
(let ((written (parameterize ((current-io-status (cons start count)))
(put-bytevector-some port bv start count))))
(loop (+ start written) (- count written))))))
--8<---------------cut here---------------end--------------->8---
We can already do something analogous on the reader side, using either
'get-bytevector-some' or the already-implemented-but-not-yet-pushed
'get-bytevector-some!'.
What do you think?
Mark
next prev parent reply other threads:[~2019-05-14 20:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-13 10:54 [PATCH] Add current-suspendable-io-status parameter Nala Ginrut
2019-05-13 10:56 ` Nala Ginrut
2019-05-13 20:54 ` Mark H Weaver
2019-05-13 23:00 ` Mark H Weaver
2019-05-14 4:22 ` Nala Ginrut
2019-05-14 20:22 ` Mark H Weaver [this message]
2019-05-15 9:31 ` Nala Ginrut
2019-05-16 0:58 ` Mark H Weaver
2019-05-17 11:07 ` Nala Ginrut
2019-05-18 23:06 ` Mark H Weaver
2019-05-15 10:09 ` tomas
2019-05-15 11:25 ` Chris Vine
2019-05-15 12:08 ` tomas
2019-05-15 11:25 ` Nala Ginrut
2019-05-15 12:10 ` tomas
2019-05-15 12:26 ` Nala Ginrut
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=878sv8kcqb.fsf@netris.org \
--to=mhw@netris.org \
--cc=guile-devel@gnu.org \
--cc=nalaginrut@gmail.com \
/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).