mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-18 09:09:42 +01:00
ab4dea344d
* concurrent echo client for stress testing * update examples for benchmarking, tweak cabal file * mark frequently-used call as unsafe for performance boost * add unsafe annotation to non-blocking C calls on critical path * more unsafe annotations -- server performance almost doubled now * one CQ for all call ops * unsafe annotation on start_batch * wait for all client threads, replace error with fail * add -O2
47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#include <string>
|
|
#include <iostream>
|
|
#include <atomic>
|
|
|
|
#include <grpc++/grpc++.h>
|
|
#include "echo.grpc.pb.h"
|
|
|
|
using namespace std;
|
|
|
|
using grpc::Server;
|
|
using grpc::ServerBuilder;
|
|
using grpc::ServerContext;
|
|
using grpc::Status;
|
|
|
|
using namespace echo;
|
|
|
|
atomic_int reqCount;
|
|
|
|
class EchoServiceImpl final : public Echo::Service {
|
|
Status DoEcho(ServerContext* ctx, const EchoRequest* req,
|
|
EchoRequest* resp) override {
|
|
resp->set_message(req->message());
|
|
return Status::OK;
|
|
}
|
|
};
|
|
|
|
class AddServiceImpl final : public Add::Service {
|
|
Status DoAdd(ServerContext* ctx, const AddRequest* req,
|
|
AddResponse* resp) override {
|
|
resp->set_answer(req->addx() + req->addy());
|
|
return Status::OK;
|
|
}
|
|
};
|
|
|
|
int main(){
|
|
string server_address("localhost:50051");
|
|
EchoServiceImpl echoService;
|
|
AddServiceImpl addService;
|
|
|
|
ServerBuilder builder;
|
|
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
|
|
builder.RegisterService(&echoService);
|
|
builder.RegisterService(&addService);
|
|
unique_ptr<Server> server(builder.BuildAndStart());
|
|
server->Wait();
|
|
return 0;
|
|
}
|