Hello!
2013/11/29 wgm:
> 最近在一个项目中需要在openresty的协程中调用lua-resty-http,我写了一个样例不知道是否合适,在大并发下是否存在问题,
最好是通过 ab 或者 weighttp 这样的工具摸拟大并发流量进行实际压力测试 :)
> 请帮我看看我的用法是否正确?
>
> function webservice(url,body)
> local res = {}
> local http = require "resty.http" --这一段引用是否正确?我很疑惑。
这一行 require 语句最好放在最外层作用域去。
>
> ws()
> local status,res = coroutine.resume(threads[i],url,body)
>
值得提醒的是,coroutine API 还是串行的。coroutine.* API 的意义在于方便地实现一些迭代器。
所以如果你需要并发多个后端 HTTP 请求,应当改用 ngx.thread API:
https://github.com/chaoslawful/lua-nginx-module#ngxthreadspawn
Regards,
-agentzh