Skip to content

Commit

Permalink
make arena patch reserve stable
Browse files Browse the repository at this point in the history
  • Loading branch information
oathdruid committed Jun 23, 2024
1 parent e672c28 commit dc093ae
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
11 changes: 2 additions & 9 deletions example/use-arena-with-brpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
DEFINE_string(connection_type, "",
"Connection type. Available values: single, pooled, short");
DEFINE_string(server, "0.0.0.0:8000", "IP Address of server");
DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds");
DEFINE_int32(timeout_ms, 500, "RPC timeout in milliseconds");

DEFINE_int32(qps, 100, "Milliseconds between consecutive requests");
DEFINE_uint64(payload_scale, 1, "");
DEFINE_uint64(payload_scale, 10, "");

void finish(::example::EchoResponse* response, ::brpc::Controller* controller) {
if (!controller->Failed()) {
Expand Down Expand Up @@ -84,19 +83,13 @@ int main(int argc, char* argv[]) {
example::EchoService_Stub stub(&channel);

::example::EchoRequest request;
int64_t expect_used = 1000000 / FLAGS_qps;
while (!brpc::IsAskedToQuit()) {
int64_t begin = ::butil::gettimeofday_us();
request.Clear();
fill(request.mutable_payload());
auto response = new ::example::EchoResponse;
auto controller = new brpc::Controller;
stub.Echo(controller, &request, response,
::google::protobuf::NewCallback(finish, response, controller));
int64_t used = ::butil::gettimeofday_us() - begin;
if (used < expect_used) {
usleep(expect_used - used);
}
}

LOG(INFO) << "EchoClient is going to quit";
Expand Down
2 changes: 2 additions & 0 deletions example/use-arena-with-brpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class EchoServiceImpl : public EchoService {
google::protobuf::Closure* done) {
brpc::ClosureGuard done_guard(done);
response->mutable_payload()->CopyFrom(request->payload());
LOG_EVERY_SECOND(INFO) << "Request SpaceUsedLong = " << request->SpaceUsedLong()
<< " Response SpaceUsedLong = " << response->SpaceUsedLong();
}
};
} // namespace example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4850,7 +4850,7 @@ index 000000000..c128b2ba0
+ size_type capacity) noexcept {
+#if __GLIBCXX__
+ size_t buffer_size = capacity + 1;
+ buffer_size = (buffer_size + 8) & static_cast<size_t>(-8);
+ buffer_size = (buffer_size + 7) & static_cast<size_t>(-8);
+ capacity = buffer_size - 1;
+#if _GLIBCXX_USE_CXX11_ABI
+ auto* buffer = reinterpret_cast<char*>(_arena->AllocateAligned(buffer_size));
Expand All @@ -4869,7 +4869,7 @@ index 000000000..c128b2ba0
+ return rep->data;
+#endif // !_GLIBCXX_USE_CXX11_ABI
+#else // !__GLIBCXX__
+ capacity = (capacity + 16) & static_cast<size_type>(-16);
+ capacity = (capacity + 15) & static_cast<size_type>(-16);
+ auto* buffer = reinterpret_cast<pointer>(_arena->AllocateAligned(capacity));
+ __builtin_memcpy(buffer, data(), size());
+ auto& rep = representation();
Expand Down
2 changes: 1 addition & 1 deletion registry/modules/protobuf/25.3.arenastring/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"integrity": "sha256-0ZZD0mW5eDgzUrMUPwTAZB7qdadSNcERzAGhNQFzGA4=",
"patch_strip": 1,
"patches": {
"arenastring.patch": "sha256-oYMEr0sJgvohN0blopeZ430dBszwYc9BhWhVHm2ikCc="
"arenastring.patch": "sha256-MY5od+YHr6z8FD6XJm9jTr70dVy3179MSOsdugFgk7g="
}
}

0 comments on commit dc093ae

Please sign in to comment.