* [PATCH 0/2] http: start migrating to pull-based I/O
@ 2016-05-21 3:03 6% Eric Wong
2016-05-21 3:03 7% ` [PATCH 1/2] http: reduce over-buffering for getline responses Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2016-05-21 3:03 UTC (permalink / raw)
To: meta
There'll be more conversions coming, but this should decouple
some of our PSGI code from Danga::Socket internals while also
providing better backpressure handling inside PublicInbox::HTTP
to avoid excessive buffering.
Eric Wong (2):
http: reduce over-buffering for getline responses
mbox: switch generation over to pull model
lib/PublicInbox/Git.pm | 2 +
lib/PublicInbox/HTTP.pm | 26 ++++++--
lib/PublicInbox/Mbox.pm | 157 +++++++++++++++---------------------------------
3 files changed, 74 insertions(+), 111 deletions(-)
^ permalink raw reply [relevance 6%]
* [PATCH 1/2] http: reduce over-buffering for getline responses
2016-05-21 3:03 6% [PATCH 0/2] http: start migrating to pull-based I/O Eric Wong
@ 2016-05-21 3:03 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-05-21 3:03 UTC (permalink / raw)
To: meta
By switching to a "pull"-based I/O model for reading
application responses, we should be able to throttle
buffering to slow clients more effectively and avoid
wasting precious RAM.
This will also allow us to more Danga::Socket-specific
knowledge out of the PSGI application and keep it
confined to PublicInbox::HTTP.
---
lib/PublicInbox/HTTP.pm | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 1ef3fb3..f69056f 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -205,7 +205,7 @@ sub response_write {
if ($alive) {
$self->event_write; # watch for readability if done
} else {
- $self->write(sub { $self->close });
+ Danga::Socket::write($self, sub { $self->close });
}
if (my $obj = $env->{'pi-httpd.inbox'}) {
# grace period for reaping resources
@@ -215,9 +215,27 @@ sub response_write {
$self->{env} = undef;
};
- if (defined $res->[2]) {
- Plack::Util::foreach($res->[2], $write);
- $close->();
+ if (defined(my $body = $res->[2])) {
+ if (ref $body eq 'ARRAY') {
+ $write->($_) foreach @$body;
+ $close->();
+ } else {
+ my $pull;
+ $pull = sub {
+ local $/ = \8192;
+ while (defined(my $buf = $body->getline)) {
+ $write->($buf);
+ if ($self->{write_buf}) {
+ $self->write($pull);
+ return;
+ }
+ }
+ $pull = undef;
+ $body->close();
+ $close->();
+ };
+ $pull->();
+ }
} else {
# this is returned to the calling application:
Plack::Util::inline_object(write => $write, close => $close);
--
EW
^ permalink raw reply related [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-05-21 3:03 6% [PATCH 0/2] http: start migrating to pull-based I/O Eric Wong
2016-05-21 3:03 7% ` [PATCH 1/2] http: reduce over-buffering for getline responses Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).