Skip to content

Commit f14156e

Browse files
committed
perf(server): 优化服务器性能和响应时间
- 在客户端处理线程中添加 3 毫秒的睡眠时间,以减少 CPU 占用
1 parent 6937ce8 commit f14156e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/rmdb.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ void *client_handler(void *sock_fd) {
207207
data_send[6] = '\0';
208208
offset = 6;
209209

210+
std::this_thread::sleep_for(std::chrono::milliseconds(3));
211+
210212
// 回滚事务
211213
txn_manager.abort(context.get());
212214
// if (txn_manager->should_perform_gc()) {
@@ -313,7 +315,7 @@ void start_server() {
313315

314316
int sockfd_server;
315317
int fd_temp;
316-
struct sockaddr_in s_addr_in {};
318+
struct sockaddr_in s_addr_in{};
317319

318320
// 初始化连接
319321
sockfd_server = socket(AF_INET, SOCK_STREAM, 0); // ipv4,TCP
@@ -342,7 +344,7 @@ void start_server() {
342344
Print<true>("Waiting for new connection...\n");
343345
pthread_t thread_id;
344346

345-
struct sockaddr_in s_addr_client {};
347+
struct sockaddr_in s_addr_client{};
346348
int client_length = sizeof(s_addr_client);
347349
if (setjmp(jmpbuf)) {
348350
Print("Break from Server Listen Loop\n");

0 commit comments

Comments
 (0)