--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
> 订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
> 发言: 请发邮件到 open...@googlegroups.com
> 退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
> 归档: http://groups.google.com/group/openresty
> 官网: http://openresty.org/
> 仓库: https://github.com/agentzh/ngx_openresty
> 教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
body = {} k=1
for i=1, 10, 1 do
local resp = {}
for j=1, 3, 1 do
local client = http.new()
client:connect(某个server)
resp[j] = make_request()
end
for j=0, 2, 1 do --读取数据
reader = resp[j].body_reader
body[k] = reader()
k = k +1
end
end
当然了,这里只是语言名词的理解和对象不同, 更准确地说:
从系统整体的角度来看它是非阻塞的,但是从这段lua脚本程序的角度来讲是“阻塞”的,
这里更好的词应该是“同步”,既然是同步,就会有些时间消耗,
ngx.thread.spawn是并行的同步,问题例子中的第一种方法是串行
同步(只不过在内核协议栈中有一定轻微程度的并行)。
好吧,貌似又是概念上的歧义。
>>>>>> > 订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
>>>>>> > 发言: 请发邮件到 open...@googlegroups.com
>>>>>> > 退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
>>>>>> > 归档: http://groups.google.com/group/openresty
>>>>>> > 官网: http://openresty.org/
>>>>>> > 仓库: https://github.com/agentzh/ngx_openresty
>>>>>> > 教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
>>>>>>
>>>>>> --
>>>>>> --
>>>>>> 邮件来自列表“openresty”,专用于技术讨论!
>>>>>> 订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
>>>>>> 发言: 请发邮件到 open...@googlegroups.com
>>>>>> 退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
>>>>>> 归档: http://groups.google.com/group/openresty
>>>>>> 官网: http://openresty.org/
>>>>>> 仓库: https://github.com/agentzh/ngx_openresty
>>>>>> 教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
>>>>>
>>>>>
>>>>> --
>>>>> --
>>>>> 邮件来自列表“openresty”,专用于技术讨论!
>>>>> 订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
>>>>> 发言: 请发邮件到 open...@googlegroups.com
>>>>> 退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
>>>>> 归档: http://groups.google.com/group/openresty
>>>>> 官网: http://openresty.org/
>>>>> 仓库: https://github.com/agentzh/ngx_openresty
>>>>> 教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
>>>>
>>>>
>>>> --
>>>> --
>>>> 邮件来自列表“openresty”,专用于技术讨论!
>>>> 订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
>>>> 发言: 请发邮件到 open...@googlegroups.com
>>>> 退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
>>>> 归档: http://groups.google.com/group/openresty
>>>> 官网: http://openresty.org/
>>>> 仓库: https://github.com/agentzh/ngx_openresty
>>>> 教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
>>>
>>>
>>> --
>>> --
>>> 邮件来自列表“openresty”,专用于技术讨论!
>>> 订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
>>> 发言: 请发邮件到 open...@googlegroups.com
>>> 退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
>>> 归档: http://groups.google.com/group/openresty
>>> 官网: http://openresty.org/
>>> 仓库: https://github.com/agentzh/ngx_openresty
>>> 教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
>>
>>
>> --
>> --
>> 邮件来自列表“openresty”,专用于技术讨论!
>> 订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
>> 发言: 请发邮件到 open...@googlegroups.com
>> 退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
>> 归档: http://groups.google.com/group/openresty
>> 官网: http://openresty.org/
>> 仓库: https://github.com/agentzh/ngx_openresty
>> 教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com

body = {} k=1
for i=1, 10, 1 do
local resp = {}
for j=1, 3, 1 do
local client = http.new()
client:connect(某个server)
resp[j] = make_request()
end
for j=0, 2, 1 do
reader = resp[j].body_reader
body[k] = reader() --读取数据 <<--
k = k +1
end
end
The body_reader iterator can be used to stream the response body in chunk sizes of your choosing, as follows:
local reader = res.body_reader repeat local chunk, err = reader(8192) if err then ngx.log(ngx.ERR, err) break end if chunk then -- process end until not chunk
If the reader is called with no arguments, the behaviour depends on the type of connection. If the response is encoded as chunked, then the iterator will return the chunks as they arrive. If not, it will simply return the entire body.
Note that the size provided is actually a maximum size. So in the chunked transfer case, you may get chunks smaller than the size you ask, as a remainder of the actual HTTP chunks.