Hello!
On Sun, Oct 27, 2013 at 10:24 PM, arthurx wrote:
>
> I used ngx.say(os.clock()) at the end of my lua script. Supposedly it is the
> whole run time of the lua script?
> However how can I monitor the run time of a specific function inside a lua
> script?
I usually use the following code to test the speed of a Lua function,
say, foo():
local begin = ngx.now()
for i = 1, 20000 do
foo()
end
ngx.update_time()
local elapsed = ngx.now() - begin
ngx.say("elapsed: ", elapsed)
The magic number 20000 is just an example, and you should adjust it
according to the actual overhead of foo() to prevent waiting for too
short or too long.
Note how we use ngx.update_time() to update the cached time in the Nginx core.
> And how can I
> monitor speed in an nginx location block? Is it just simple ab?
Well, ab works. Just always specify the -k option to save the TCP
connect() overhead.
Regards,
-agentzh