batching in client

This commit is contained in:
Hieu Hoang 2017-02-20 13:01:44 +00:00
parent c316b64d34
commit e39d0c8f8a
2 changed files with 22 additions and 10 deletions

View File

@ -5,17 +5,26 @@ import time
import sys
filePath = sys.argv[1]
print filePath
batchSize = int(sys.argv[2])
#print filePath
with open(filePath) as f:
batchCount = 0
batch = ""
for line in f:
#print line
line = line[:-1]
#print line
ws = create_connection("ws://localhost:8080/translate")
ws.send(line)
result=ws.recv()
print(result)
ws.close()
#time.sleep(5)
batchCount = batchCount + 1
batch = batch + line
if batchCount == batchSize:
ws = create_connection("ws://localhost:8080/translate")
batch = batch[:-1]
ws.send(batch)
result=ws.recv()
print(result)
ws.close()
#time.sleep(5)
batchCount = 0
batch = ""

View File

@ -39,6 +39,7 @@ boost::python::list translate(boost::python::list& in)
for(int lineNum = 0; lineNum < boost::python::len(in); ++lineNum) {
std::string line = boost::python::extract<std::string>(boost::python::object(in[lineNum]));
cerr << "line=" << line << endl;
maxiBatch->push_back(SentencePtr(new Sentence(god_, lineNum++, line)));
@ -77,7 +78,9 @@ boost::python::list translate(boost::python::list& in)
for (auto&& result : results) {
std::stringstream ss;
Printer(god_, *result.get().get(), ss);
output.append(ss.str());
string str = ss.str();
cerr << "output=" << str << endl;
output.append(str);
}
return output;