[Catalyst] $c->write() buffering?

John Napiorkowski jjn1056 at yahoo.com
Thu Oct 31 21:30:54 GMT 2013

Recent releases of Catalyst makes it possible to stream write, although you=
 need to be careful when using a blocking web server (long stream will of c=
ourse block the available listener).

Older versions of Catalyst had similar ability with the write method, I nev=
er used it, and would be happen to get patches or test cases to make it wor=
k as we'd like.

Here's a link to an example, this one assume AnyEvent as a loop, but you co=
uld use a similar technique with any web server, as long as you don't mind =


If you follow that, you will see stuff 'stream' as you wish unless there is=
 some buffering going on at some other level of the stack.


On Thursday, October 31, 2013 4:22 PM, Daniel J. Luke <dluke at geeklair.net> =

I replicated this today outside of Catalyst (just a small FCGI/FCGI::ProcMa=
nager test script). If anyone else has seen this/fixed it, I'd appreciate a=
 pointer. I'll report back to the list if/when I get it resolved so that th=
ere's an answer in the list archives for future people to google otherwise.

On Oct 31, 2013, at 10:12 AM, Daniel J. Luke <dluke at geeklair.net> wrote:
> We're actually running Catalyst::Runtime 5.80031 (currently), so I believ=
e it's using Catalyst::Engine::FastCGI which just does *STDOUT->syswrite()
> =

> I guess I try to do some testing with newer Catalyst (and maybe alternate=
 deployment methods), to see if that changes anything. Looking through the =
Changelog, I didn't see anything specifically related to this, though (alth=
ough I imagine the Plack stuff makes it somewhat different in the more rece=
nt releases). =

> =

> On Oct 30, 2013, at 11:03 PM, Hailin Hu <i at h2l.name> wrote:
>> It is an engine relevant stuff.
>> Find which engine you are using ( for example, Plack::Handler::FCGI )
>> and look around codes around write(r), you may find something.
>> Good luck :)
>> =

>> On Wed, Oct 30, 2013 at 9:51 AM, Daniel J. Luke <dluke at geeklair.net> wro=
>>> I've got some legacy CGI code that does a bunch of processing and uses =
the old hack of $| =3D 1; print "foo\n"; do_work(); print "foo done\n"; etc=
. (solution #1 from http://wiki.catalystframework.org/wiki/longcomputations)
>>> =

>>> While I'll eventually convert it to a job queue, I'd like to create an =
output-identical implementation first with Catalyst, however it seems like =
I'm getting output buffering when I don't want it.
>>> =

>>> As a very simple test, I've set up apache 2.2, mod_fastcgi (FastCgiExte=
rnalServer with -flush and without -flush) and a method like this:
>>> =

>>> sub test: Local {
>>>=A0  my ($self, $c) =3D @_;
>>> =

>>>=A0  $c->res->body('');
>>>=A0  $c->response->content_type( 'text/plain; charset=3Dutf-8' );
>>>=A0  $c->finalize_headers;
>>> =

>>>=A0  my $i;
>>>=A0  for($i=3D1;$i<8;$i++) {
>>>=A0 =A0 =A0  $c->write("$i: foo bar baz\n");
>>>=A0 =A0 =A0  sleep(1);
>>>=A0  }
>>> }
>>> =

>>> I see all the data at once in my browser instead of a line every second=
, and with tcpdump, can see that all of the data is coming back in one pack=
et and not in 8+ smaller packets like I expect. If I make the string that g=
ets passed to write longer, I get several packets, but all at once (and not=
 with each iteration through the for loop).
>>> =

>>> Am I missing something obvious? Is there some way to get the behavior I=
'm expecting?

Daniel J. Luke=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=3D=3D=3D=3D=3D=3D=3D+=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

| *---------------- dluke at geeklair.net ----------------* |=A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

| *-------------- http://www.geeklair.net -------------* |=A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=3D=3D=3D=3D=3D=3D=3D+=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

|=A0  Opinions expressed are mine and do not necessarily=A0  |=A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

|=A0 =A0 =A0 =A0 =A0 reflect the opinions of my employer.=A0 =A0 =A0 =A0 =
=A0 |=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =


List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20131031/a8a58=

More information about the Catalyst mailing list