Skip to content

Commit f88dbfe

Browse files
committed
perf: 减少缓冲区大小并优化网络读取操作
将BUFFER_LENGTH从8192减少到1024以降低内存使用 使用read替代recv进行网络数据读取 使用std::move优化ast::parse_tree传递
1 parent 013c6a0 commit f88dbfe

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/common/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ See the Mulan PSL v2 for more details. */
1515
#include <cstdint>
1616
#include <string>
1717

18-
#define BUFFER_LENGTH 8192
18+
#define BUFFER_LENGTH 1024
1919

2020
/** Cycle detection is performed every CYCLE_DETECTION_INTERVAL milliseconds. */
2121
extern std::chrono::milliseconds cycle_detection_interval;

src/rmdb.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void *client_handler(void *sock_fd) {
155155
while (true) {
156156
Print<true>("Waiting for request...\n");
157157

158-
i_recvBytes = recv(fd, data_recv, BUFFER_LENGTH, 0);
158+
i_recvBytes = read(fd, data_recv, BUFFER_LENGTH);
159159
data_recv[i_recvBytes] = '\0';
160160

161161
if (i_recvBytes == 0) {
@@ -195,7 +195,7 @@ void *client_handler(void *sock_fd) {
195195
if (yyparse(scanner) == 0) {
196196
if (ast::parse_tree != nullptr) {
197197
try {
198-
std::shared_ptr<Query> query = analyze.do_analyze(ast::parse_tree);
198+
std::shared_ptr<Query> query = analyze.do_analyze(std::move(ast::parse_tree));
199199
yy_delete_buffer(buf, scanner);
200200
finish_analyze = true;
201201
std::shared_ptr<Plan> plan = optimizer.plan_query(query, context.get());
@@ -315,7 +315,7 @@ void start_server() {
315315

316316
int sockfd_server;
317317
int fd_temp;
318-
struct sockaddr_in s_addr_in {};
318+
struct sockaddr_in s_addr_in{};
319319

320320
// 初始化连接
321321
sockfd_server = socket(AF_INET, SOCK_STREAM, 0); // ipv4,TCP
@@ -344,7 +344,7 @@ void start_server() {
344344
Print<true>("Waiting for new connection...\n");
345345
pthread_t thread_id;
346346

347-
struct sockaddr_in s_addr_client {};
347+
struct sockaddr_in s_addr_client{};
348348
int client_length = sizeof(s_addr_client);
349349
if (setjmp(jmpbuf)) {
350350
Print("Break from Server Listen Loop\n");

0 commit comments

Comments
 (0)