liuxuting commented on issue #2944:
URL: https://github.com/apache/brpc/issues/2944#issuecomment-2862475350

   server.cpp压测脚本:
   #include <stdlib.h>
   #include <unistd.h>
   #include <vector>
   #include <gflags/gflags.h>
   #include "butil/atomicops.h"
   #include "butil/fast_rand.h"
   #include "butil/logging.h"
   #include "brpc/rdma/rdma_helper.h"
   #include "brpc/server.h"
   #include "brpc/channel.h"
   #include "bthread/bthread.h"
   #include "bvar/latency_recorder.h"
   #include "bvar/variable.h"
   #include "test.pb.h"
   #include <thread>
   #include "butil/time.h"
   #ifdef BRPC_WITH_RDMA
   
   DEFINE_int32(attachment_size, -1, "Attachment size is used (in Bytes)");
   DEFINE_bool(echo_attachment, false, "Select whether attachment should be 
echo");
   DEFINE_string(connection_type, "single", "Connection type of the channel");
   DEFINE_string(protocol, "baidu_std", "Protocol type.");
   
   DEFINE_string(server_addr, "0.0.0.0:8002", "Address of server");
   DEFINE_string(server_addr_tcp, "0.0.0.0:8002", "Address of server");
   butil::atomic<uint64_t> g_last_time(0);
   
   
   
   
   namespace test {
       class PerfTestServiceImpl : public PerfTestService {
       public:
           PerfTestServiceImpl() {}
           ~PerfTestServiceImpl() {}
   
           void Test(google::protobuf::RpcController* cntl_base,
                     const PerfTestRequest* request,
                     PerfTestResponse* response,
                     google::protobuf::Closure* done) {
               brpc::ClosureGuard done_guard(done);
               uint64_t last = g_last_time.load(butil::memory_order_relaxed);
               uint64_t now = butil::monotonic_time_us();
               if (now > last && now - last > 100000) {
                   if (g_last_time.exchange(now, butil::memory_order_relaxed) 
== last) {
                       
response->set_cpu_usage(bvar::Variable::describe_exposed("process_cpu_usage"));
                   } else {
                       response->set_cpu_usage("");
                   }
               } else {
                   response->set_cpu_usage("");
               }
               if (request->echo_attachment()) {
                   brpc::Controller* cntl =
                       static_cast<brpc::Controller*>(cntl_base);
                   
cntl->response_attachment().append(cntl->request_attachment());
               }
           }
       };
   }
   
   int server(int argc, char* argv[], bool use_rdma) {
       GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
   
       brpc::Server server;
       test::PerfTestServiceImpl perf_test_service_impl;
   
       if (server.AddService(&perf_test_service_impl,
                               brpc::SERVER_DOESNT_OWN_SERVICE) != 0) {
           LOG(ERROR) << "Fail to add service";
           return -1;
       }
       g_last_time.store(0, butil::memory_order_relaxed);
   
       brpc::ServerOptions options;
       options.use_rdma = use_rdma;
       if (use_rdma) {
           if (server.Start(FLAGS_server_addr.c_str(), &options) != 0) {
               LOG(ERROR) << "Fail to start EchoServer";
               return -1;
           }
       } else {
           if (server.Start(FLAGS_server_addr_tcp.c_str(), &options) != 0) {
               LOG(ERROR) << "Fail to start EchoServer";
               return -1;
           }
       }
   
       server.RunUntilAskedToQuit();
       return 0;
   }
   
   int main(int argc, char* argv[]) {
       std::thread server_thread([&]()
       {
           server(argc, argv, false);
       });
       std::cout << "=====start server2=====" << std::endl;
       std::this_thread::sleep_for(std::chrono::milliseconds(10000));
       server_thread.detach();
   
       std::thread server2_thread([&](){
           server(argc, argv, true);
       });
       server2_thread.join();
   }
   
   #else
   
   int main(int argc, char* argv[]) {
       LOG(ERROR) << " brpc is not compiled with rdma. To enable it, please 
refer to https://github.com/apache/brpc/blob/master/docs/en/rdma.md";;
       return 0;
   }
   
   #endif


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to