all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: storm@cua.dk (Kim F. Storm)
Cc: emacs-devel@gnu.org
Subject: Re: Fix for slow process output processing (please test).
Date: 16 Dec 2003 11:23:32 +0100	[thread overview]
Message-ID: <m3fzflcb8b.fsf@kfs-l.imdomain.dk> (raw)
In-Reply-To: <x5zndtmo5v.fsf@lola.goethe.zz>

David.Kastrup@t-online.de (David Kastrup) writes:

> > David Kastrup and others have reported very slow processing of process
> > output, particularly with the Linux kernel's scheduler giving emacs
> > too much attention while starving the processing producing the output.
> > 
> > Below is a patch which introduces a small delay on reading output from
> > such processes, without using global delays in processing other events
> > (this is done by temporarily removing the process' file descriptor from
> > the call to select and use a short timeout on the select instead.
> 
> I have glanced over that patch.  There is one problem I see with it:
> if indeed the generating process is able to produce lots of data with
> a single write call, Emacs will be throttling its input without a
> purpose.

With the patch, emacs only throttles if it reads less than 1024 bytes
at a time from the process -- i.e. if the process is unable to produce
data fast enough to fill emacs's read buffer.

So if you have a process which manages to write a lot of data in one
write, emacs should happily read that data with no throttling.

Of course, if it has just read some (slower) data with throttling, the
first few 1024 packages will still be trottled (max 100ms total), but
then it would read the rest at full speed.

> 
> This situation is quite more probable when we have a multiprocessor
> machine or when the input is generated by some network process (so
> again, on a different CPU).

If you have a multi-processor system, and your process generates
output at a steady (fast) stream, emacs will not do throttling on that
process.  Only if that process slows down, you will see throttling --
but how would you notice that?

And network traffic is not throttled by this patch!

> 
> The best behavior would be
> a) don't bother reading from the pipe for a while if it is not yet
>    full.
> b) process it immediately once it is completely full.

c) or process it after some timeout if there is any data in the pipe

Yes, there are various ways to accomplish this, but I would rather try
to find a simple solution which works reasonably well in most/all
cases, rather than a more complex (and perhaps o/s specific) solution
that I'm not really sure will work much better in general.

> 
> The select call does not offer any possibility to say "wake up
> immediately if there is such an amount of data".  And we need the
> select call to poll other input, so we can't just use blocking I/O
> with a timeout set (which would probably be the best solution if we
> had only to worry about a single source of input).
> 
> `Enterprise level' solutions would probably be:
> a) use blocking I/O with a timeout set in a separate thread.  When
> the timeout hits or the read completes, whatever has accumulated in
> the corresponding input buffer is marked for processing and made
> available to the main Emacs.
> b) use aio_read to request a full pipe worth of data.  If no signal
> announces the availability of the data, some timeout may be used to
> cancel the aio_read if there is data available, but not a full pipe
> worth of it.
> 
> Of course, those solutions are more operating system specific than the
> current one.  It may well be that there are few applications that will
> turn out worse by throttling Emacs to something like 8kB/20ms or so.
> 

We may go for more advanced solutions, if the current patch does not
solve the problem (maybe with some tuning of the throttling
parameters).

But I would like some feedback on the effects of the current patch
first (also on multi-processor systems if possible); maybe it just
happens to be "good enough" in practice.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

  reply	other threads:[~2003-12-16 10:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-16  1:21 Fix for slow process output processing (please test) Kim F. Storm
2003-12-16  2:14 ` David Kastrup
2003-12-16  3:34 ` David Kastrup
2003-12-16 10:23   ` Kim F. Storm [this message]
2003-12-16 11:51     ` David Kastrup
2003-12-16 13:24       ` Kim F. Storm
2004-01-03 15:12         ` David Kastrup
2004-01-04 23:00           ` Kim F. Storm
2004-01-03 22:07 ` Eric Hanchrow
2004-01-04 22:42   ` Kim F. Storm
2004-01-05 15:57     ` David Kastrup
2004-01-05 19:09       ` Eli Zaretskii
2004-01-05 19:39         ` David Kastrup
2004-01-05 19:52         ` Jason Rumney
2004-01-05 23:28           ` Kim F. Storm
2004-01-05 23:16             ` Jason Rumney
2004-01-05 23:44               ` David Kastrup
2004-01-06  0:23                 ` Jason Rumney
2004-01-07  0:40               ` Kim F. Storm
2004-01-05 23:35       ` Kim F. Storm
2004-01-05 22:50         ` David Kastrup
2004-01-06  0:09           ` Kim F. Storm

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

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

  git send-email \
    --in-reply-to=m3fzflcb8b.fsf@kfs-l.imdomain.dk \
    --to=storm@cua.dk \
    --cc=emacs-devel@gnu.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.