# Fastcgi chunked data

**URL:** <https://www.ruby-forum.com/t/fastcgi-chunked-data/210862>\
**Category:** NGINX\
**Created:** [August 19, 2011, 2:39am UTC](https://www.ruby-forum.com/t/fastcgi-chunked-data/210862 "2011-08-19T02:39:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [August 19, 2011, 2:39am UTC](https://www.ruby-forum.com/t/fastcgi-chunked-data/210862/1 "2011-08-19T02:39:30Z")

</div>

I have a fastcgi server connection that send chunks of data. I would  
like to have the chucks of data written to downstream, not buffered.

I want to send chunked data from the server, but nginx buffers the data,  
I want to flush the data immediately.

I have found the “trunk” 1.1.0 code almost works.

1\> The event happens  
2\> the pipe is read  
3\> something is checked???  
4\> the data is buffered, not written downstream  
5\> try to write down stream, but no buffer, Why?  
5\> checks upstream again  
6\> starts timer again

I have traced the code but I get lost at

[debug] 2842#0: \*4 pipe recv chain: -2  
src/event/ngx\_event\_pipe.c:272  
n = p-\>upstream-\>recv\_chain(p-\>upstream, chain);

```
        ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
                       "pipe recv chain: %z", n);

```

AND

why there is no buffer to write?  
[debug] 2842#0: \*4 pipe write downstream: 1 0000000000000000

2011/08/18 17:26:01 [debug] 2842#0: \*4 post event 0000000001FF1BF0  
2011/08/18 17:26:01 [debug] 2842#0: \*4 post event 0000000002005400  
2011/08/18 17:26:01 [debug] 2842#0: \*4 delete posted event  
0000000002005400  
2011/08/18 17:26:01 [debug] 2842#0: \*4 http upstream request:  
“/mafw/weiqi.psh?” 1  
2011/08/18 17:26:01 [debug] 2842#0: \*4 http upstream dummy handler  
2011/08/18 17:26:01 [debug] 2842#0: \*4 delete posted event  
0000000001FF1BF0  
2011/08/18 17:26:01 [debug] 2842#0: \*4 http upstream request:  
“/mafw/weiqi.psh?” 0  
2011/08/18 17:26:01 [debug] 2842#0: \*4 http upstream process upstream  
2011/08/18 17:26:01 [debug] 2842#0: \*4 pipe read upstream: 1  
2011/08/18 17:26:01 [debug] 2842#0: \*4 readv: 2:4096  
2011/08/18 17:26:01 [debug] 2842#0: \*4 pipe recv chain: 144  
2011/08/18 17:26:01 [debug] 2842#0: \*4 readv: 2:4096  
2011/08/18 17:26:01 [debug] 2842#0: \*4 readv() not ready (11: Resource  
temporarily unavailable)  
2011/08/18 17:26:01 [debug] 2842#0: \*4 pipe recv chain: -2  
2011/08/18 17:26:01 [debug] 2842#0: \*4 pipe buf free s:0 t:1 f:0  
0000000001FC9750, pos 0000000001FC9750, size: 3368 file: 0, size: 0  
2011/08/18 17:26:01 [debug] 2842#0: \*4 pipe buf free s:0 t:1 f:0  
0000000001FC7730, pos 0000000001FC7730, size: 0 file: 0, size: 0  
2011/08/18 17:26:01 [debug] 2842#0: \*4 pipe write downstream: 1  
0000000000000000  
2011/08/18 17:26:01 [debug] 2842#0: \*4 pipe write busy: 0  
2011/08/18 17:26:01 [debug] 2842#0: \*4 pipe write: out:0000000000000000,  
f:0  
2011/08/18 17:26:01 [debug] 2842#0: \*4 pipe read upstream: 0  
2011/08/18 17:26:01 [debug] 2842#0: \*4 pipe buf free s:0 t:1 f:0  
0000000001FC9750, pos 0000000001FC9750, size: 3368 file: 0, size: 0  
2011/08/18 17:26:01 [debug] 2842#0: \*4 pipe buf free s:0 t:1 f:0  
0000000001FC7730, pos 0000000001FC7730, size: 0 file: 0, size: 0  
2011/08/18 17:26:01 [debug] 2842#0: \*4 event timer del: 20:  
1313659596126  
2011/08/18 17:26:01 [debug] 2842#0: \*4 event timer add: 20:  
60000:1313659621126

---

<div class="post-metadata">

**Author:** ![Shaun\_savage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@Shaun\_savage](https://www.ruby-forum.com/u/Shaun_savage)\
**Post date:** [August 19, 2011, 6:45am UTC](https://www.ruby-forum.com/t/fastcgi-chunked-data/210862/2 "2011-08-19T06:45:45Z")

</div>

That’s a lot of debugging when you could just have read the wiki  
instead: [Module ngx\_http\_fastcgi\_module](http://wiki.nginx.org/HttpFcgiModule#fastcgi_buffers)

“If you want to disable buffering to disk for all replies that are  
greater than the FastCGI buffers and transfer data synchronously to the  
client set fastcgi\_max\_temp\_file\_size to 0.”

Posted at Nginx Forum:

> **[Re: Fastcgi chunked data](https://forum.nginx.org/read.php?2,214015,214018#msg-214018)**
>
> I have a fastcgi server connection that send chunks of data. I would like to have the chucks of data written to downstream, not buffered. I want to send chunked data from the server, but nginx buffers the data, I want to flush the data immediately. I...

---

<div class="post-metadata">

**Author:** ![Shaun\_savage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@Shaun\_savage](https://www.ruby-forum.com/u/Shaun_savage)\
**Post date:** [August 19, 2011, 9:40am UTC](https://www.ruby-forum.com/t/fastcgi-chunked-data/210862/3 "2011-08-19T09:40:00Z")

</div>

Hello!

On Fri, Aug 19, 2011 at 08:39:02AM +0800, Shaun savage wrote:

> I have a fastcgi server connection that send chunks of data. I would  
> like to have the chucks of data written to downstream, not buffered.
> 
> I want to send chunked data from the server, but nginx buffers the data,  
> I want to flush the data immediately.

As of now nginx will always buffer fastcgi response up to full buffer  
(see fastcgi\_buffers directive) filled.

If you really need data to be flushed immediately, you may try the  
patch from here:

> **[upstream keepalive - call for testing](http://mailman.nginx.org/pipermail/nginx/2011-August/028324.html)**

It is to address completely different problem, but as a side  
effect with the patch complete fastcgi records will be sent without  
further buffering.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Shaun\_savage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9a140/32.png) [@Shaun\_savage](https://www.ruby-forum.com/u/Shaun_savage)\
**Post date:** [August 19, 2011, 11:13am UTC](https://www.ruby-forum.com/t/fastcgi-chunked-data/210862/4 "2011-08-19T11:13:23Z")

</div>

I am not reading a file from disk, I am generating the data from a  
program.  
I added

fastcgi\_max\_temp\_file\_size 0;

but is still buffers the data in the FastCGI buffers.

the size i am chunking is only 144 bytes
