Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixing query-server/client
  • Loading branch information
searchivairus committed Feb 8, 2018
1 parent e53183c commit 6c1a64b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 16 deletions.
6 changes: 4 additions & 2 deletions query_server/cpp_client_server/QueryService_server.cpp
Expand Up @@ -17,6 +17,7 @@
#include <mutex>
#include <thread>
#include <chrono>
#include <iostream>

#include "QueryService.h"
#include <thrift/protocol/TBinaryProtocol.h>
Expand All @@ -40,6 +41,7 @@
#include "knnqueue.h"
#include "methodfactory.h"
#include "init.h"
#include "logging.h"
#include "ztimer.h"

#define MAX_SPIN_LOCK_QTY 1000000
Expand Down Expand Up @@ -448,7 +450,7 @@ void ParseCommandLineForServer(int argc, char*argv[],
po::notify(vm);
} catch (const exception& e) {
Usage(argv[0], ProgOptDesc);
LOG(LIB_FATAL) << e.what() << endl;
LOG(LIB_FATAL) << e.what();
}

if (vm.count("help") ) {
Expand Down Expand Up @@ -532,7 +534,7 @@ int main(int argc, char *argv[]) {
QueryTimeParams
);

initLibrary(LogFile.empty() ? LIB_LOGSTDERR:LIB_LOGFILE, LogFile.c_str());
initLibrary(0, LogFile.empty() ? LIB_LOGSTDERR:LIB_LOGFILE, LogFile.c_str());

ToLower(DistType);

Expand Down
2 changes: 1 addition & 1 deletion query_server/cpp_client_server/makefile
Expand Up @@ -2,7 +2,7 @@ NON_METRIC_SPACE_LIBRARY=../../similarity_search/
NON_METRIC_SPACE_LIBRARY_INC=$(NON_METRIC_SPACE_LIBRARY)/include
NON_METRIC_SPACE_LIBRARY_LIB=$(NON_METRIC_SPACE_LIBRARY)/release

LIBS= -lthrift -lNonMetricSpaceLib -lgsl -lgslcblas -llshkit -lboost_program_options
LIBS= -lthrift -lNonMetricSpaceLib -lboost_program_options

CXXFLAGS += -I$(NON_METRIC_SPACE_LIBRARY_INC) -I./gen-thrift/
# Enable C++11
Expand Down
33 changes: 33 additions & 0 deletions query_server/cpp_client_server/makefile.with_extras
@@ -0,0 +1,33 @@
NON_METRIC_SPACE_LIBRARY=../../similarity_search/
NON_METRIC_SPACE_LIBRARY_INC=$(NON_METRIC_SPACE_LIBRARY)/include
NON_METRIC_SPACE_LIBRARY_LIB=$(NON_METRIC_SPACE_LIBRARY)/release

LIBS= -lthrift -lNonMetricSpaceLib -lgsl -lgslcblas -llshkit -lboost_program_options

CXXFLAGS += -I$(NON_METRIC_SPACE_LIBRARY_INC) -I./gen-thrift/
# Enable C++11
CXXFLAGS += -std=c++11
# OMP flags
CXXFLAGS += -fopenmp
# Debug flags
#CXXFLAGS += -g
#CXXFLAGS += -g -O3
CXXFLAGS += -O3

BIN=query_server query_client

all: $(BIN)

clean:
rm -f *.o gen-thrift/*.o $(BIN)

THRIFT_SRC=$(wildcard gen-thrift/*.cpp)
THRIFT_OBJ=$(patsubst %.cpp,%.o,$(THRIFT_SRC))

# Note -pthread: this enables threads!!!
query_server: $(THRIFT_OBJ) QueryService_server.o gen-thrift/*.h makefile $(NON_METRIC_SPACE_LIBRARY_LIB)/libNonMetricSpaceLib.a
$(CXX) -o$@ $(THRIFT_OBJ) QueryService_server.o -L/usr/local/lib -L$(NON_METRIC_SPACE_LIBRARY_LIB) $(LIBS) -pthread -fopenmp

query_client: $(THRIFT_OBJ) QueryClient.o gen-thrift/*.h makefile $(NON_METRIC_SPACE_LIBRARY_LIB)/libNonMetricSpaceLib.a
$(CXX) -o$@ $(THRIFT_OBJ) QueryClient.o -L/usr/local/lib -L$(NON_METRIC_SPACE_LIBRARY_LIB) $(LIBS) -pthread -fopenmp

8 changes: 4 additions & 4 deletions query_server/python_client/protocol/QueryService.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions query_server/python_client/query_client.py
Expand Up @@ -14,7 +14,7 @@ from datetime import datetime
import argparse

def error_exit(s):
print "Error: %s" % s
print("Error: %s" % s)
sys.exit(1)

parser = argparse.ArgumentParser()
Expand All @@ -36,7 +36,7 @@ retObj = args.retObj
retExternId = args.retObj

try:
print "Host %s socket %d" % (host,port)
print("Host %s socket %d" % (host,port))
# Make socket
transport = TSocket.TSocket(host, port)
# Buffering is critical. Raw sockets are very slow
Expand All @@ -62,13 +62,13 @@ try:
k = args.knn
if not args.range is None:
error_exit('Range search is not allowed if the KNN search is specified!')
print "Running %d-NN search" % k
print("Running %d-NN search" % k)
res = client.knnQuery(k, queryObj, retObj, retExternId)
elif not args.range is None:
r = args.range
if not args.knn is None:
error_exit('KNN search is not allowed if the range search is specified')
print "Running range search, range=%f" % r
print("Running range search, range=%f" % r)
res = client.rangeQuery(r, queryObj, retObj, retExternId)
else:
error_exit("Wrong search type %s" % searchType)
Expand All @@ -79,18 +79,18 @@ try:

elapsed = diff.seconds * 1e3 + diff.microseconds / 1e3

print "Finished in %f ms" % elapsed
print("Finished in %f ms" % elapsed)

for e in res:
s=''
if retExternId:
s='externId=' + e.externId
print "id=%d dist=%f %s" % (e.id, e.dist, s)
print("id=%d dist=%f %s" % (e.id, e.dist, s))
if retObj:
print e.obj
print(e.obj)

# Close!
transport.close()

except Thrift.TException, tx:
print '%s' % (tx.message)
except(Thrift.TException, tx):
print('%s' % (tx.message))

0 comments on commit 6c1a64b

Please sign in to comment.