Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add InitLimit #346

Merged
merged 14 commits into from
Jul 6, 2024
Merged

Conversation

luky116
Copy link
Collaborator

@luky116 luky116 commented Jun 10, 2024

fix #315

Summary by CodeRabbit

  • 新功能
    • 增加了资源限制初始化功能,确保PikiwiDB能够根据允许的最大客户端数量调整资源限制,以确保其正常运行。

Copy link

coderabbitai bot commented Jun 10, 2024

流程概要

src/pikiwidb.cc 文件中,添加了 InitLimit() 函数,该函数用于根据允许的最大客户端数量设置 PikiwiDB 的资源限制。如果当前限制低于指定的最大值,函数会相应地调整限制。此外,在初始化日志之前,主函数调用了 InitLimit() 来调整文件限制。

变更

文件路径 变更摘要
src/pikiwidb.cc 新增了对 <sys/resource.h> 的引入,新增了 InitLimit() 函数,用于根据 max_clients 配置调整文件限制,并在初始化日志之前调用 InitLimit()

时序图

sequenceDiagram
    participant Main
    participant InitLimit
    Main->>InitLimit: 调用 InitLimit()
    InitLimit->>System: 获取当前文件限制
    System->>InitLimit: 返回文件限制
    InitLimit->>System: 调整文件限制(如果需要)
    System->>InitLimit: 确认新文件限制
    InitLimit-->>Main: 完成调用
    Main->>Logs: 初始化日志
Loading

与关联问题的评估

目标 处理情况 解释
检查文件描述符数量(#315

数据库飞跃天际,
最大连接不可低迷,
文件限制轻轻调,
稳定运行乐淘淘。


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the ✏️ Feature New feature or request label Jun 10, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eec3030 and e9f11f9.

Files selected for processing (1)
  • src/pikiwidb.cc (2 hunks)
Additional comments not posted (1)
src/pikiwidb.cc (1)

282-282: InitLimit 函数的调用位置适当,确保在服务器初始化之前设置文件描述符限制。

src/pikiwidb.cc Outdated
Comment on lines 221 to 238
static int InitLimit() {
rlimit limit;
rlim_t maxfiles = g_config.max_clients;
if (getrlimit(RLIMIT_NOFILE, &limit) == -1) {
WARN("getrlimit error: ", strerror(errno));
} else if (limit.rlim_cur < maxfiles) {
rlim_t old_limit = limit.rlim_cur;
limit.rlim_cur = maxfiles;
limit.rlim_max = maxfiles;
if (setrlimit(RLIMIT_NOFILE, &limit) != -1) {
WARN( "your 'limit -n ' of ", old_limit, " is not enough for PikiwiDB to start. PikiwiDB have successfully reconfig it to " , limit.rlim_cur);
} else {
ERROR("your 'limit -n ' of " , old_limit, " is not enough for PikiwiDB to start. PikiwiDB can not reconfig it(", strerror(errno), "), do it by yourself");
return -1;
}
}
return 0;
}
Copy link

@coderabbitai coderabbitai bot Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

调整文件描述符限制的逻辑看起来是正确的,但是在日志消息中使用逗号连接字符串可能会导致问题。建议使用格式化字符串。

- WARN("getrlimit error:  ", strerror(errno));
+ WARN("getrlimit error: %s", strerror(errno));
- WARN( "your 'limit -n ' of ", old_limit, " is not enough for PikiwiDB to start. PikiwiDB have successfully reconfig it to " , limit.rlim_cur);
+ WARN("your 'limit -n ' of %ld is not enough for PikiwiDB to start. PikiwiDB have successfully reconfig it to %ld", old_limit, limit.rlim_cur);
- ERROR("your 'limit -n ' of " , old_limit, " is not enough for PikiwiDB to start. PikiwiDB can not reconfig it(", strerror(errno), "), do it by yourself");
+ ERROR("your 'limit -n ' of %ld is not enough for PikiwiDB to start. PikiwiDB can not reconfig it(%s), do it by yourself", old_limit, strerror(errno));
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static int InitLimit() {
rlimit limit;
rlim_t maxfiles = g_config.max_clients;
if (getrlimit(RLIMIT_NOFILE, &limit) == -1) {
WARN("getrlimit error: ", strerror(errno));
} else if (limit.rlim_cur < maxfiles) {
rlim_t old_limit = limit.rlim_cur;
limit.rlim_cur = maxfiles;
limit.rlim_max = maxfiles;
if (setrlimit(RLIMIT_NOFILE, &limit) != -1) {
WARN( "your 'limit -n ' of ", old_limit, " is not enough for PikiwiDB to start. PikiwiDB have successfully reconfig it to " , limit.rlim_cur);
} else {
ERROR("your 'limit -n ' of " , old_limit, " is not enough for PikiwiDB to start. PikiwiDB can not reconfig it(", strerror(errno), "), do it by yourself");
return -1;
}
}
return 0;
}
static int InitLimit() {
rlimit limit;
rlim_t maxfiles = g_config.max_clients;
if (getrlimit(RLIMIT_NOFILE, &limit) == -1) {
WARN("getrlimit error: %s", strerror(errno));
} else if (limit.rlim_cur < maxfiles) {
rlim_t old_limit = limit.rlim_cur;
limit.rlim_cur = maxfiles;
limit.rlim_max = maxfiles;
if (setrlimit(RLIMIT_NOFILE, &limit) != -1) {
WARN("your 'limit -n ' of %ld is not enough for PikiwiDB to start. PikiwiDB have successfully reconfig it to %ld", old_limit, limit.rlim_cur);
} else {
ERROR("your 'limit -n ' of %ld is not enough for PikiwiDB to start. PikiwiDB can not reconfig it(%s), do it by yourself", old_limit, strerror(errno));
return -1;
}
}
return 0;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luky116, 感谢您的修改!如果有任何其他问题或需要进一步的帮助,请随时告知。


Learnings added
Learnt from: luky116
PR: OpenAtomFoundation/pikiwidb#346
File: src/pikiwidb.cc:0-0
Timestamp: 2024-07-01T23:31:59.313Z
Learning: When suggesting changes to log messages, ensure to use formatted strings instead of concatenation for better readability and to avoid potential issues.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e9f11f9 and 7741a42.

Files selected for processing (1)
  • src/pikiwidb.cc (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/pikiwidb.cc

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7741a42 and bea4007.

Files selected for processing (1)
  • src/pikiwidb.cc (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/pikiwidb.cc

src/pikiwidb.cc Outdated Show resolved Hide resolved
@luky116 luky116 closed this Jun 29, 2024
@luky116 luky116 reopened this Jun 29, 2024
@AlexStocks
Copy link
Contributor

AlexStocks commented Jul 1, 2024

请及时处理 Review 的comment,并更新最新代码

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Please update the latest code in time

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bea4007 and f973c82.

Files selected for processing (1)
  • src/pikiwidb.cc (3 hunks)
Additional comments not posted (2)
src/pikiwidb.cc (2)

15-15: 包含 <sys/resource.h> 是必要的。

此包含是为了处理系统资源限制所必需的。


288-288: main 函数中调用 InitLimit 是合理的。

在初始化日志之前调用 InitLimit 函数,以确保 PikiwiDB 运行时具有所需的资源限制。

src/pikiwidb.cc Outdated
Comment on lines 222 to 244
static int InitLimit() {
rlimit limit;
rlim_t maxfiles = g_config.max_clients;
if (getrlimit(RLIMIT_NOFILE, &limit) == -1) {
WARN("getrlimit error: {}", strerror(errno));
} else if (limit.rlim_cur < maxfiles) {
rlim_t old_limit = limit.rlim_cur;
limit.rlim_cur = maxfiles;
limit.rlim_max = maxfiles;
if (setrlimit(RLIMIT_NOFILE, &limit) != -1) {
WARN("your 'limit -n ' of {} is not enough for PikiwiDB to start. PikiwiDB have successfully reconfig it to ",
old_limit, limit.rlim_cur);
} else {
ERROR(
"your 'limit -n ' of {} is not enough for PikiwiDB to start. PikiwiDB can not reconfig it({}), do it by "
"yourself",
old_limit, strerror(errno));

return -1;
}
}
return 0;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改进日志消息的格式化。

当前使用字符串连接的方式记录日志,建议使用格式化字符串以提高可读性和性能。

- WARN("getrlimit error:  ", strerror(errno));
+ WARN("getrlimit error: %s", strerror(errno));
- WARN( "your 'limit -n ' of ", old_limit, " is not enough for PikiwiDB to start. PikiwiDB have successfully reconfig it to " , limit.rlim_cur);
+ WARN("your 'limit -n ' of %ld is not enough for PikiwiDB to start. PikiwiDB have successfully reconfig it to %ld", old_limit, limit.rlim_cur);
- ERROR("your 'limit -n ' of " , old_limit, " is not enough for PikiwiDB to start. PikiwiDB can not reconfig it(", strerror(errno), "), do it by yourself");
+ ERROR("your 'limit -n ' of %ld is not enough for PikiwiDB to start. PikiwiDB can not reconfig it(%s), do it by yourself", old_limit, strerror(errno));
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static int InitLimit() {
rlimit limit;
rlim_t maxfiles = g_config.max_clients;
if (getrlimit(RLIMIT_NOFILE, &limit) == -1) {
WARN("getrlimit error: {}", strerror(errno));
} else if (limit.rlim_cur < maxfiles) {
rlim_t old_limit = limit.rlim_cur;
limit.rlim_cur = maxfiles;
limit.rlim_max = maxfiles;
if (setrlimit(RLIMIT_NOFILE, &limit) != -1) {
WARN("your 'limit -n ' of {} is not enough for PikiwiDB to start. PikiwiDB have successfully reconfig it to ",
old_limit, limit.rlim_cur);
} else {
ERROR(
"your 'limit -n ' of {} is not enough for PikiwiDB to start. PikiwiDB can not reconfig it({}), do it by "
"yourself",
old_limit, strerror(errno));
return -1;
}
}
return 0;
}
static int InitLimit() {
rlimit limit;
rlim_t maxfiles = g_config.max_clients;
if (getrlimit(RLIMIT_NOFILE, &limit) == -1) {
WARN("getrlimit error: %s", strerror(errno));
} else if (limit.rlim_cur < maxfiles) {
rlim_t old_limit = limit.rlim_cur;
limit.rlim_cur = maxfiles;
limit.rlim_max = maxfiles;
if (setrlimit(RLIMIT_NOFILE, &limit) != -1) {
WARN("your 'limit -n ' of %ld is not enough for PikiwiDB to start. PikiwiDB have successfully reconfig it to %ld", old_limit, limit.rlim_cur);
} else {
ERROR("your 'limit -n ' of %ld is not enough for PikiwiDB to start. PikiwiDB can not reconfig it(%s), do it by yourself", old_limit, strerror(errno));
return -1;
}
}
return 0;
}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f973c82 and ba34cd1.

Files selected for processing (1)
  • src/pikiwidb.cc (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/pikiwidb.cc

@luky116
Copy link
Collaborator Author

luky116 commented Jul 1, 2024

请及时处理 Review 的comment,并更新最新代码

嗯嗯,已处理

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Please handle Review comments in a timely manner and update the latest code

OK, processed

AlexStocks
AlexStocks previously approved these changes Jul 2, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ba34cd1 and 575c765.

Files selected for processing (1)
  • src/pikiwidb.cc (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/pikiwidb.cc

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 575c765 and 8dc19ee.

Files selected for processing (1)
  • src/pikiwidb.cc (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/pikiwidb.cc

AlexStocks
AlexStocks previously approved these changes Jul 2, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8dc19ee and bf058cb.

Files selected for processing (1)
  • src/pikiwidb.cc (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/pikiwidb.cc

@panlei-coder panlei-coder merged commit 91e4863 into OpenAtomFoundation:unstable Jul 6, 2024
6 checks passed
chanfun-ren pushed a commit to chanfun-ren/pikiwidb that referenced this pull request Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check fd number
4 participants