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

neko.Web.cacheModule problem in nginx + tora -fcgi #6

Closed
R32 opened this issue Sep 28, 2015 · 1 comment
Closed

neko.Web.cacheModule problem in nginx + tora -fcgi #6

R32 opened this issue Sep 28, 2015 · 1 comment

Comments

@R32
Copy link
Contributor

R32 commented Sep 28, 2015

win7 32 + haxe 3.2 + neko 2.0.0

nginx conf

location /app {
  fastcgi_pass 127.0.0.1:6666;
### path to file
  fastcgi_param SCRIPT_FILENAME R:/test/bin/app.n;

  fastcgi_param DOCUMENT_URI $document_uri;
  fastcgi_param REMOTE_ADDR $remote_addr;
  fastcgi_param QUERY_STRING q=$uri&$query_string;
  fastcgi_param SERVER_NAME $server_name;
  fastcgi_param REQUEST_METHOD $request_method;         
  fastcgi_param CONTENT_TYPE $content_type;
  fastcgi_param CONTENT_LENGTH $content_length;     
  fastcgi_param REMOTE_PORT $remote_port;
  fastcgi_param SERVER_ADDR $server_addr;
  fastcgi_param SERVER_PORT $server_port;
}

app.n

class App {
    static var i:Int = 0;

    static function main() {
        Sys.print("[set_cacheModule] ");
        neko.Web.cacheModule(run);
        run();
    }

    static function run() Sys.print(i++ +", "); 
}

http requst test:

class Request { 
    static var s2 = Sys.time() * 1000  + 2000;

    static function main() {
        for(i in 0...5){
            neko.vm.Thread.create(run);
        }
        Sys.sleep(5);
    }

    static function run() {
        while (true)    {
            var time = Sys.time() * 1000;           
            if(time > s2){
                Sys.println("time:" + time + ", respond:" +
                    haxe.Http.requestUrl("http://localhost/app/?time=" + time));    
                break;
            }
            //Sys.sleep(0.01);
        }       
    }
}
> haxe -cp src -main Request -neko req.n -cmd "neko req.n"
time:1443423148875, respond:[set_cacheModule] 0,
time:1443423148875, respond:[set_cacheModule] 0,
time:1443423148875, respond:1,
time:1443423148875, respond:1,
time:1443423148875, respond:2,

if I use nekotools server handle app.n ,the "cacheModule problem" will not occur:

@ncannasse
Copy link
Member

It's perfectly normal. In tora you can have several instances of the same module being cached, each module will be usable by one thread so you don't have to use multithreading mutexes to protect your static variables. The allocation/desallocation of instances is automatically handled by tora.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants