Skip to content
Permalink
Browse files
Merge pull request #1486 from wwbmmm/nshead_rpc_dump_and_replay
Support nshead protocol dump and replay
  • Loading branch information
wwbmmm committed Mar 28, 2022
2 parents 2839f32 + 3323eb3 commit ef35b2c7d2174bf909cbdd1a60e69e1e09b150f3
Showing 4 changed files with 22 additions and 2 deletions.
@@ -1,4 +1,4 @@
r31658后,brpc能随机地把一部分请求写入一些文件中,并通过rpc_replay工具回放。目前支持的协议有:baidu_std, hulu_pbrpc, sofa_pbrpc, http。
r31658后,brpc能随机地把一部分请求写入一些文件中,并通过rpc_replay工具回放。目前支持的协议有:baidu_std, hulu_pbrpc, sofa_pbrpc, http, nshead

# 获取工具

@@ -26,6 +26,7 @@
#include "brpc/socket.h" // Socket
#include "brpc/server.h" // Server
#include "brpc/span.h"
#include "brpc/rpc_dump.h"
#include "brpc/details/server_private_accessor.h"
#include "brpc/details/controller_private_accessor.h"
#include "brpc/nshead_service.h"
@@ -229,6 +230,15 @@ void ProcessNsheadRequest(InputMessageBase* msg_base) {
return;
}

// for nshead sample request
SampledRequest* sample = AskToBeSampled();
if (sample) {
sample->meta.set_protocol_type(PROTOCOL_NSHEAD);
sample->meta.set_nshead(p, sizeof(nshead_t)); // nshead
sample->request = msg->payload;
sample->submit(start_parse_us);
}

// Switch to service-specific error.
non_service_error.release();
MethodStatus* method_status = service->_status;
@@ -42,4 +42,7 @@ message RpcDumpMeta {

// hulu_pbrpc
optional bytes user_data = 8;

// nshead
optional bytes nshead = 9;
}
@@ -27,6 +27,7 @@
#include <brpc/server.h>
#include <brpc/rpc_dump.h>
#include <brpc/serialized_request.h>
#include <brpc/nshead_message.h>
#include <brpc/details/http_message.h>
#include "info_thread.h"

@@ -133,6 +134,7 @@ static void* replay_thread(void* arg) {
const int thread_offset = g_thread_offset.fetch_add(1, butil::memory_order_relaxed);
double req_rate = FLAGS_qps / (double)FLAGS_thread_num;
brpc::SerializedRequest req;
brpc::NsheadMessage nshead_req;
std::deque<int64_t> timeq;
size_t MAX_QUEUE_SIZE = (size_t)req_rate;
if (MAX_QUEUE_SIZE < 100) {
@@ -161,7 +163,7 @@ static void* replay_thread(void* arg) {
brpc::Controller* cntl = new brpc::Controller;
req.Clear();

brpc::SerializedRequest* req_ptr = &req;
google::protobuf::Message* req_ptr = &req;
cntl->reset_sampled_request(sample_guard.release());
if (sample->meta.protocol_type() == brpc::PROTOCOL_HTTP) {
brpc::HttpMessage http_message;
@@ -173,6 +175,11 @@ static void* replay_thread(void* arg) {
}
cntl->request_attachment() = http_message.body().movable();
req_ptr = NULL;
} else if (sample->meta.protocol_type() == brpc::PROTOCOL_NSHEAD) {
nshead_req.Clear();
memcpy(&nshead_req.head, sample->meta.nshead().c_str(), sample->meta.nshead().length());
nshead_req.body = sample->request;
req_ptr = &nshead_req;
} else if (sample->meta.attachment_size() > 0) {
sample->request.cutn(
&req.serialized_data(),

0 comments on commit ef35b2c

Please sign in to comment.