This is an automated email from the ASF dual-hosted git repository.
dmeden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 9d241b2372 RPC client: Increase message buffer size. (#9970)
9d241b2372 is described below
commit 9d241b23723351c60c075b2a4f7e42c147a9423f
Author: Damian Meden <[email protected]>
AuthorDate: Mon Jul 17 13:07:37 2023 +0100
RPC client: Increase message buffer size. (#9970)
We need this to be bigger to eventually allocate a large number of
records/metrics. To avoid having issues with having such large buffer in
the stack we do allocate the the buffer in the heap.
This change also moves from ts::FixedBufferWriter to
swoc::FixedBufferWriter.
---
include/shared/rpc/IPCSocketClient.h | 4 ++--
include/shared/rpc/RPCClient.h | 9 +++++----
mgmt/rpc/server/unit_tests/test_rpcserver.cc | 6 +++---
src/shared/rpc/IPCSocketClient.cc | 6 +++---
4 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/include/shared/rpc/IPCSocketClient.h
b/include/shared/rpc/IPCSocketClient.h
index 841f254069..250dee0e18 100644
--- a/include/shared/rpc/IPCSocketClient.h
+++ b/include/shared/rpc/IPCSocketClient.h
@@ -27,7 +27,7 @@
#include <sys/socket.h>
#include <sys/un.h>
-#include <tscore/BufferWriter.h>
+#include <swoc/BufferWriter.h>
namespace shared::rpc
{
@@ -57,7 +57,7 @@ struct IPCSocketClient {
self_reference send(std::string_view data);
/// Read all the content from the socket till the passed buffer is full.
- ReadStatus read_all(ts::FixedBufferWriter &bw);
+ ReadStatus read_all(swoc::FixedBufferWriter &bw);
/// Closes the socket.
void
diff --git a/include/shared/rpc/RPCClient.h b/include/shared/rpc/RPCClient.h
index f2d7240428..f869f150cf 100644
--- a/include/shared/rpc/RPCClient.h
+++ b/include/shared/rpc/RPCClient.h
@@ -26,7 +26,7 @@
#include <yaml-cpp/yaml.h>
#include <tscore/I_Layout.h>
-#include <tscore/BufferWriter.h>
+#include <swoc/BufferWriter.h>
#include "IPCSocketClient.h"
#include "yaml_codecs.h"
@@ -38,9 +38,9 @@ namespace shared::rpc
///
class RPCClient
{
- // Large buffer, as we may query a full list of records.
+ // Large buffer, as we may query a full list of records(metrics can be a lot
bigger).
// TODO: should we add a parameter to increase the buffer? or maybe a record
limit on the server's side?
- static constexpr int BUFFER_SIZE{356000};
+ static constexpr size_t BUFFER_SIZE{35600000};
public:
RPCClient() : _client(Layout::get()->runtimedir + "/jsonrpc20.sock") {}
@@ -53,7 +53,8 @@ public:
invoke(std::string_view req)
{
std::string text; // for error messages.
- ts::LocalBufferWriter<BUFFER_SIZE> bw;
+ std::unique_ptr<char[]> buf(new char[BUFFER_SIZE]);
+ swoc::FixedBufferWriter bw{buf.get(), BUFFER_SIZE};
try {
_client.connect();
if (!_client.is_closed()) {
diff --git a/mgmt/rpc/server/unit_tests/test_rpcserver.cc
b/mgmt/rpc/server/unit_tests/test_rpcserver.cc
index 377aec3a58..dab5050412 100644
--- a/mgmt/rpc/server/unit_tests/test_rpcserver.cc
+++ b/mgmt/rpc/server/unit_tests/test_rpcserver.cc
@@ -33,7 +33,7 @@
#include "swoc/swoc_file.h"
-#include <tscore/BufferWriter.h>
+#include <swoc/BufferWriter.h>
#include "ts/ts.h"
#include "rpc/jsonrpc/JsonRPC.h"
@@ -190,7 +190,7 @@ struct ScopedLocalSocket : shared::rpc::IPCSocketClient {
std::string
read()
{
- ts::LocalBufferWriter<32000> bw;
+ swoc::LocalBufferWriter<32000> bw;
auto ret = super::read_all(bw);
if (ret == ReadStatus::NO_ERROR) {
return {bw.data(), bw.size()};
@@ -201,7 +201,7 @@ struct ScopedLocalSocket : shared::rpc::IPCSocketClient {
std::string
query(std::string_view msg)
{
- ts::LocalBufferWriter<32000> bw;
+ swoc::LocalBufferWriter<32000> bw;
auto ret = connect().send(msg).read_all(bw);
if (ret == ReadStatus::NO_ERROR) {
return {bw.data(), bw.size()};
diff --git a/src/shared/rpc/IPCSocketClient.cc
b/src/shared/rpc/IPCSocketClient.cc
index d39cf3a32e..477bae6659 100644
--- a/src/shared/rpc/IPCSocketClient.cc
+++ b/src/shared/rpc/IPCSocketClient.cc
@@ -61,7 +61,7 @@ IPCSocketClient ::send(std::string_view data)
}
IPCSocketClient::ReadStatus
-IPCSocketClient::read_all(ts::FixedBufferWriter &bw)
+IPCSocketClient::read_all(swoc::FixedBufferWriter &bw)
{
if (this->is_closed()) {
// we had a failure.
@@ -69,10 +69,10 @@ IPCSocketClient::read_all(ts::FixedBufferWriter &bw)
}
ReadStatus readStatus{ReadStatus::UNKNOWN};
while (bw.remaining()) {
- swoc::MemSpan<char> span{bw.auxBuffer(), bw.remaining()};
+ swoc::MemSpan<char> span{bw.aux_data(), bw.remaining()};
const ssize_t ret = ::read(_sock, span.data(), span.size());
if (ret > 0) {
- bw.fill(ret);
+ bw.commit(ret);
if (bw.remaining() > 0) { // some space available.
continue;
} else {