Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple benchmark, is there something wrong with my code? #2

Closed
twojcik opened this issue Mar 24, 2012 · 4 comments

Comments

Projects
None yet
2 participants
@twojcik
Copy link

commented Mar 24, 2012

Hi,
I'm really intrigued in your work of using nginx as app server. I've tried simple benchmark of nginx and lua duo, and it gave me about 100k requests per second, but when I added redis call to code, it dropped to about 18k , is it normal or there is something wrong with my code?

Many thanks,
Tadek

worker_processes 8;

events {

worker_connections 16384;
}
http {
server {

access_log off;

    listen 8080;
    location / {
        default_type text/html;
        content_by_lua '
            local redis = require "resty.redis"
        local red = redis:new()

        local ok, err = red:connect("127.0.0.1", 6379)
        if not ok then
            ngx.say("failed to connect: ", err)
            return
        end

        res, err = red:set("dog", "an aniaml")
        if not ok then
            ngx.say("failed to set dog: ", err)
            return
        ngx.say("dog: ", res)
        end
        ';
    }
}

}

@agentzh

This comment has been minimized.

Copy link
Member

commented Mar 25, 2012

You code does not utilize the connection pools for redis. I think you should put your redis connection to the connection pool by calling the set_keepalive method on the resty.redis object. See the documentation:

https://github.com/agentzh/lua-resty-redis

Also, using LuaJIT 2.0 with your nginx will help too :)

@twojcik

This comment has been minimized.

Copy link
Author

commented Mar 25, 2012

Thanks !

Now when benchmarking hello word with content_by_lua, I have 120k rps. When issuing request to redis I have abut 47-50k rps. When running similar node.js server I had about 30k rps, so it was only ~40% worse that nginx/lua combo.
Is ./configure --with-luajit enough to run nginx with LuaJIT enabled ?
Is config below uses keep-alive from end user perspective? I've checked headers and it returns connection:keep-alive. Can I disable it?
I'm hestitating between node.js and nginx/lua combo and still not sure which one to choose.
Do you still LB before such nginx/lua servers? Or load distribution is done at DNS level?

Many thanks,
Tadek

worker_processes 6;

events {

worker_connections 26384;
}
http {
server {

access_log off;

listen 8080;
location / {
    default_type text/html;
    content_by_lua '
    local redis = require "resty.redis"
    local red = redis:new()

    local ok, err = red:connect("127.0.0.1", 6379)
    if not ok then
      ngx.say("failed to connect: ", err)
      return
    end

    res, err = red:set("dog", "an aniaml")
    if not ok then
      ngx.say("failed to set dog: ", err)
      return

    end
    ngx.say("dog: ", res)
    local ok, err = red:set_keepalive(0, 1000)
    if not ok then
      ngx.say("failed to set keepalive: ", err)
      return
    end
    ';

}

}
}

@agentzh

This comment has been minimized.

Copy link
Member

commented Mar 25, 2012

On Sun, Mar 25, 2012 at 7:57 PM, Tadeusz Wjcik <
reply@reply.github.com

wrote:

Now when benchmarking hello word with content_by_lua, I have 120k rps.
When issuing request to redis I have abut 47-50k rps. When running similar
node.js server I had about 30k rps, so it was only ~40% worse that
nginx/lua combo.
Is ./configure --with-luajit enough to run nginx with LuaJIT enabled ?

Yes.

Is config below uses keep-alive from end user perspective? I've checked
headers and it returns connection:keep-alive. Can I disable it?

You can disable HTTP keepalive in Nginx by adding the following line to
your nginx.conf:

keepalive_timeout 0;

See http://wiki.nginx.org/HttpCoreModule#keepalive_timeout

I'm hestitating between node.js and nginx/lua combo and still not sure

which one to choose.

It'll also be fun to compare the CPU and RAM usage of these two at full
load ;)

Also, configuring CPU affinity for Nginx worker processes may help to
improve performance a lot too. See
http://wiki.nginx.org/CoreModule#worker_cpu_affinity

BTW, I'm still optimizing the ngx_lua cosocket mechanism that
lua-resty-redis (and other lua-resty-* libraries) relies on ;)

Do you still LB before such nginx/lua servers? Or load distribution is done

at DNS level?

Different companies have different strategies here. Some puts something
like LVS before the nginx/lua servers and some just do this on the DNS
level.

Best regards,
-agentzh

@twojcik

This comment has been minimized.

Copy link
Author

commented Mar 25, 2012

Many many thanks Agentzh :)

@twojcik twojcik closed this Mar 25, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.