How to allow multiple connections to Dancer2

泪湿孤枕 提交于 2019-12-12 02:36:37

问题


I am using Perl Dancer2 as the RESTful service framework with the basic setting (using command

dancer2 -a MyWeb::App

to generate template files and add "get" routes in the auto-generated MyWeb-App/lib/MyWeb/App.pm file). Recently I found out that when one request needs a long period of time to finish, the server is locked to only serve that request. For example

get '/' => sub {# simple request to redirect to a static page
    template 'index'; #template directive Templates all go into the views/
};
get '/compute' => sub{
    for (my $i=0;$i<1000000;$i++){
         wait(1000);  #simulate long computation time 
    }
    return "Done!";
};

When firstly in one tab http://myhost.com/compute is entered, in another tab the link http://myhost.com/ won't display anything until the previous /compute route finishes, which seems to me that only one connection is allowed at a time. The question is how to set up the Dancer2 server to allow multiple connections, i.e. the two tabs mentioned above can be run at the same time?

Many thanks!


回答1:


How are you deploying your Dancer2 app? If you're using plackup, then you should realise that the default server that plackup uses only supports a single connection. But you can use the -s option to change to something like Starman, which supports multiple connections. See Dancer2::Manual::Deployment for more details.

If that's not the case, then you need to tell us more about your application. Is it possible that requests are blocking because they all need access to some shared resource?



来源:https://stackoverflow.com/questions/43760883/how-to-allow-multiple-connections-to-dancer2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!