Hello!
On Fri, Aug 15, 2014 at 1:32 PM, info wrote:
>
> This is Windows you know :) things work a bit differently.
>
But basic things and concepts still remain the same :)
>
> Only because the issue is the same (how to test for a failed link).
>
Then you should make it clearer :) For ngx_lua's builtin connection
pool, there is actually a mechanism that automatically removes a
connection when dubious new read events happen on that connection such
that it cannot get reused by future requests. So the chance that you
get a broken connection from the pool is much smaller for relatively
idle servers. Also, the getreusedtimes() result can also be used on
the Lua land to actively give up connections that have been reused for
certain amount of times (like 10K times or 100K times). Basically,
passive error handling should be good enough here.
On that lua-resty-mysql ticket, an active ping query involves extra
overhead in an extra MySQL round trip (meaning more system calls, more
computation on the MySQL server side, and etc). I don't think it
should be recommended :)
Where can I found the source code?
> The mysql example shows how each worker gets its data, the failed link thing
> is a GeoIP example I'm working on.
> I've run tests on the mysql sample with 1.000 clients each with 1.000
> requests on 2 workers and can't see any blocking going on.
>
You should test the following mysql query with a *single* nginx worker
process configured:
select sleep(1);
And check how many requests per second you can have with certain
concurrency level (say, 100) for a single nginx worker.
If it's nonblocking, then for the concurrency level of 100 (like ab's
-c100 option), you should get somewhere near 100 req/sec. The actual
number measured can be a bit smaller than 100 req/sec, but should not
be far away. If it's blocking, then you can only get 1 req/sec (yes,
no kidding). If you're getting a rate larger than 100 req/sec, then
you must be incorrectly caching the query result inside nginx, which
defeats the purpose of this test :)
I've tested lua-resty-mysql with a *single* nginx worker and the
"select sleep(1)" MySQL query, and the command "ab -c100 -n 200 -k
localhost/t" gives the result after 2.037 seconds:
Requests per second: 98.20 [#/sec] (mean)
Quite close to the value in theory, 100.00 #/sec. So it is not
blocking nginx event loop. On the other hand, if it is blocking, then
the "ab" command will take way longer to complete and will eventually
print the something like 0.95 req/sec.
> Tests on the GeoIP sample with a lua_shared_dict SQL cache on 4 workers,
> 10.000 clients each with 5.000 requests and pcall's does a nice 2k/sec rate,
> so if there is something blocking I can't see it :)
>
Try testing the case that pcall actually catches some error :) And
compare that with simply returning and checking an error string ;)
Also, I cannot really parse your numbers like "10.000". Are you using
the dot (.) as the decimal point as in 3.14, or just as "," to
visually isolate zeros (as in 25,000,000)?
Again, you could do much better than 2k/sec with true I/O multiplexing
because even when you block the nginx event loop, you can still get 2k
req/sec by just strictly serially accessing MySQL. The 2k req/sec rate
alone cannot prove anything. You need to carefully design an
experiment. For example, you should really use the "select sleep(1)"
MySQL query above to quickly test if your MySQL queries are blocking
the nginx event loop :)
Finally, as I've stated in my previous mail, the "nonblocking magic"
cannot happen if you're not using cosockets nor subrequests when
running Lua code doing socket I/O atop the official ngx_lua module :)
Regards,
-agentzh