Hello!
On Mon, Jun 1, 2015 at 5:33 PM, guanglinlv wrote:
> I am using lua-resty-http and proxy_response to proxy stream output, i get a
> performance problem that high cpu utilization,up to 98 percent.
>
Time to profile! See
http://openresty.org/#Profiling
Everytime I see a CPU hog, I'll definitely sample some flame graphs ;)
You're encouraged to post your flame graphs here so that I can give
you advices with ease.
> nginx has only start one worker. I get the debug of nginx worker thread with
> commad strace -p <nginx-worker-pid> -c:
>
> it tells that most of time is invoke receive and writev.
I wonder if your process indeed spend most of the CPU time in the
syscalls. Maybe it's busy with userland code? A C-land flame graph can
give us a big picture.
> I guess it because
> tcpsock:receive is invoked at the lua coroutine in a loop, more details in
> _chunked_body_reader function.
>
Ensure that you handle errors of your receive() calls (and any other
I/O calls) properly in your Lua code. Failing to handle errors may
make your loop enter dead busy looping depending on how you write your
loop.
> Is tcpsock:receive invoke system call receive each time?
It depends on whether there's remaining data in the cosocket receive
buffers (userland buffers).
> Is there some more
> performance way like event notify?
>
The tcpsock:receive *is* based on event notification under the hood.
> any suggestion and solution is big help for me.
>
See above.
Best regards,
-agentzh