mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-08-16 15:00:33 +03:00
Reorganization of server options. Added options for sesssion cache.
This commit is contained in:
parent
51bc36d131
commit
faaf0bdf87
@ -22,6 +22,7 @@ mingw/MosesGUI/Ui_credits.py
|
||||
mingw/MosesGUI/Ui_mainWindow.py
|
||||
moses/TranslationModel/UG
|
||||
moses/server
|
||||
moses/parameters
|
||||
phrase-extract/pcfg-common
|
||||
phrase-extract/syntax-common
|
||||
randlm
|
||||
|
@ -66,6 +66,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#include "server/Translator.h"
|
||||
#include "server/Optimizer.h"
|
||||
#include "server/Updater.h"
|
||||
#include "moses/parameters/ServerOptions.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
@ -147,21 +148,15 @@ int
|
||||
run_as_server()
|
||||
{
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
int port;
|
||||
params.SetParameter(port, "server-port", 8080);
|
||||
bool isSerial;
|
||||
params.SetParameter(isSerial, "serial", false);
|
||||
string logfile;
|
||||
params.SetParameter(logfile, "server-log", string("/dev/null"));
|
||||
size_t num_threads;
|
||||
params.SetParameter(num_threads, "threads", size_t(10));
|
||||
if (isSerial) VERBOSE(1,"Running server in serial mode." << endl);
|
||||
ServerOptions sopts(params);
|
||||
if (sopts.is_serial) VERBOSE(1,"Running server in serial mode." << endl);
|
||||
|
||||
xmlrpc_c::registry myRegistry;
|
||||
|
||||
xmlrpc_c::methodPtr const translator(new MosesServer::Translator(num_threads));
|
||||
xmlrpc_c::methodPtr const updater(new MosesServer::Updater);
|
||||
xmlrpc_c::methodPtr const optimizer(new MosesServer::Optimizer);
|
||||
xmlrpc_c::methodPtr const
|
||||
translator(new MosesServer::Translator(sopts.num_threads)),
|
||||
updater(new MosesServer::Updater),
|
||||
optimizer(new MosesServer::Optimizer);
|
||||
|
||||
myRegistry.addMethod("translate", translator);
|
||||
myRegistry.addMethod("updater", updater);
|
||||
@ -170,16 +165,18 @@ run_as_server()
|
||||
xmlrpc_c::serverAbyss myAbyssServer(
|
||||
xmlrpc_c::serverAbyss::constrOpt()
|
||||
.registryP(&myRegistry)
|
||||
.portNumber(port) // TCP port on which to listen
|
||||
.logFileName(logfile)
|
||||
.portNumber(sopts.port) // TCP port on which to listen
|
||||
.logFileName(sopts.logfile)
|
||||
.allowOrigin("*")
|
||||
.maxConn((unsigned int)num_threads)
|
||||
.maxConn(sopts.num_threads)
|
||||
);
|
||||
|
||||
XVERBOSE(1,"Listening on port " << port << endl);
|
||||
if (isSerial) {
|
||||
while(1) myAbyssServer.runOnce();
|
||||
} else myAbyssServer.run();
|
||||
XVERBOSE(1,"Listening on port " << sopts.port << endl);
|
||||
if (sopts.is_serial)
|
||||
{
|
||||
while(true) myAbyssServer.runOnce();
|
||||
}
|
||||
else myAbyssServer.run();
|
||||
|
||||
std::cerr << "xmlrpc_c::serverAbyss.run() returned but should not." << std::endl;
|
||||
// #pragma message("BUILDING MOSES WITH SERVER SUPPORT")
|
||||
@ -188,7 +185,6 @@ run_as_server()
|
||||
std::cerr << "Moses was compiled without server support." << endl;
|
||||
#endif
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -214,6 +214,10 @@ Parameter::Parameter()
|
||||
AddParam(server_opts,"server", "Run moses as a translation server.");
|
||||
AddParam(server_opts,"server-port", "Port for moses server");
|
||||
AddParam(server_opts,"server-log", "Log destination for moses server");
|
||||
AddParam(server_opts,"session-timeout",
|
||||
"Timeout for sessions, e.g. '2h30m' or 1d (=24h)");
|
||||
AddParam(server_opts,"session-cache-size", string("Max. number of sessions cached.")
|
||||
+"Least recently used session is dumped first.");
|
||||
AddParam(server_opts,"serial", "Run server in serial mode, processing only one request at a time.");
|
||||
|
||||
po::options_description irstlm_opts("IRSTLM Options");
|
||||
|
57
moses/parameters/ServerOptions.cpp
Normal file
57
moses/parameters/ServerOptions.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// -*- mode: c++; cc-style: gnu -*-
|
||||
#include "ServerOptions.h"
|
||||
#include <boost/foreach.hpp>
|
||||
#include <string>
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
// parse the session timeout specifciation for moses server
|
||||
// Format is "<number>d[<number>[h[<number>m[<number>s]]]]".
|
||||
// If none of 'dhms' is given, it is assumed that it's seconds.
|
||||
// Specs can be combined, e.g. 2h30m, although it's probably nonsense
|
||||
// to be so specific.
|
||||
size_t
|
||||
parse_timespec(std::string const& spec)
|
||||
{
|
||||
size_t t = 0, timeout = 0;
|
||||
BOOST_FOREACH(char const& c, spec)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
t = t * 10 + c - '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c == 'd') timeout = t * 24 * 3600;
|
||||
else if (c == 'h') timeout += t * 3600;
|
||||
else if (c == 'm') timeout += t * 60;
|
||||
else if (c == 's') timeout += t;
|
||||
else UTIL_THROW2("Can't parse specification '" << spec
|
||||
<< " at " << HERE);
|
||||
t = 0;
|
||||
}
|
||||
}
|
||||
return timeout;
|
||||
}
|
||||
|
||||
ServerOptions::
|
||||
ServerOptions(Parameter const& P)
|
||||
{
|
||||
init(P);
|
||||
}
|
||||
|
||||
bool
|
||||
ServerOptions::
|
||||
init(Parameter const& P)
|
||||
{
|
||||
P.SetParameter(this->port, "server-port", 8080);
|
||||
P.SetParameter(this->is_serial, "serial", false);
|
||||
P.SetParameter(this->logfile, "server-log", std::string("/dev/null"));
|
||||
P.SetParameter(this->num_threads, "threads", uint32_t(10));
|
||||
P.SetParameter(this->session_cache_size, "session-cache_size",25UL);
|
||||
std::string timeout_spec;
|
||||
P.SetParameter(timeout_spec, "session-timeout",std::string("30m"));
|
||||
this->session_timeout = parse_timespec(timeout_spec);
|
||||
return true;
|
||||
}
|
||||
} // namespace Moses
|
20
moses/parameters/ServerOptions.h
Normal file
20
moses/parameters/ServerOptions.h
Normal file
@ -0,0 +1,20 @@
|
||||
// -*- mode: c++; cc-style: gnu -*-
|
||||
#include <string>
|
||||
#include "moses/Parameter.h"
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
struct
|
||||
ServerOptions
|
||||
{
|
||||
int port;
|
||||
bool is_serial;
|
||||
std::string logfile;
|
||||
uint32_t num_threads;
|
||||
size_t session_timeout;
|
||||
size_t session_cache_size;
|
||||
bool init(Parameter const& param);
|
||||
ServerOptions(Parameter const& param);
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user