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

fix(engine): adjust thread pool size calculation for FeatureCityGmlReader #899

Merged
merged 3 commits into from
Feb 21, 2025

Conversation

miseyu
Copy link
Contributor

@miseyu miseyu commented Feb 21, 2025

Overview

What I've done

What I haven't done

How I tested

Screenshot

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • Refactor

    • Revised the system’s internal concurrency handling. The update now limits the number of parallel processing threads to a fixed, lower value, ensuring controlled resource usage and consistent performance, particularly under heavy workload conditions.
  • Chores

    • Updated version number for the engine package from "0.0.15" to "0.0.16".
    • Updated version number for the plateau-gis-quality-checker package from "0.0.12" to "0.0.13".

@miseyu miseyu self-assigned this Feb 21, 2025
@miseyu miseyu requested a review from a team as a code owner February 21, 2025 14:33
Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

Warning

Rate limit exceeded

@miseyu has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e603097 and 7a988f7.

📒 Files selected for processing (1)
  • engine/runtime/action-processor/src/feature/reader/citygml/processor.rs (1 hunks)

Walkthrough

This pull request modifies the thread pool calculation in the build method of the FeatureCityGmlReaderFactory. The divisor used to compute the thread count is changed from 2f32 to 4f32, and the upper limit is reduced from 32 to 4. As a result, the factory will always create at least 1 but no more than 4 threads, thereby restricting the concurrency level without affecting any public interface.

Changes

File Change Summary
engine/.../processor.rs Adjusted thread pool calculation in build method: divisor changed from 2f32 to 4f32 and maximum threads limited from 32 to 4.
engine/Cargo.toml Version updated from 0.0.15 to 0.0.16.
engine/plateau-gis-quality-checker/.../Cargo.toml Version updated from 0.0.12 to 0.0.13.

Possibly related PRs

Poem

I'm a rabbit in the codewarren, hopping with glee,
Threads now count by fours – a simpler, breezier spree.
With limits set to four, my digital burrow's neat,
Fewer threads mean a calm pace, oh so sweet.
Code carrots crunch, and bugs take their leave,
Celebrating these changes on a bright spring eve!
🐇💻


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

netlify bot commented Feb 21, 2025

Deploy Preview for reearth-flow canceled.

Name Link
🔨 Latest commit 7a988f7
🔍 Latest deploy log https://app.netlify.com/sites/reearth-flow/deploys/67b891a8b2720f0008dda937

Copy link
Contributor

@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

🔭 Outside diff range comments (1)
engine/runtime/action-processor/src/feature/reader/citygml/processor.rs (1)

128-130: ⚠️ Potential issue

Fix inconsistency in thread count reporting.

The num_threads() method returns 2, which is inconsistent with the actual thread pool size calculation that uses a maximum of 4 threads.

Update the method to return the actual thread count:

-    fn num_threads(&self) -> usize {
-        2
-    }
+    fn num_threads(&self) -> usize {
+        self.thread_pool.lock().current_num_threads()
+    }
🧹 Nitpick comments (2)
engine/runtime/action-processor/src/feature/reader/citygml/processor.rs (2)

83-89: Consider making thread pool size configurable.

While reducing the thread count can help avoid contention, hardcoding the divisor (4) and maximum threads (4) might not be optimal for all workloads and hardware configurations.

Consider making these values configurable through the FeatureCityGmlReaderParam:

 pub struct FeatureCityGmlReaderParam {
     dataset: Expr,
     flatten: Option<bool>,
+    thread_divisor: Option<f32>,
+    max_threads: Option<usize>,
 }

Then update the thread calculation to use these parameters with fallback to defaults:

let thread_divisor = params.thread_divisor.unwrap_or(4.0);
let max_threads = params.max_threads.unwrap_or(4);
let size = (num_cpus::get() as f32 / thread_divisor).trunc() as usize;
let threads_num = if size < 1 { 1 } else { std::cmp::min(size, max_threads) };

143-159: Improve thread pool management.

The current implementation could benefit from better thread pool management:

  1. Consider implementing graceful shutdown
  2. Add task cancellation support for long-running operations

Consider implementing a cancellation mechanism using tokio::sync::CancellationToken:

use tokio::sync::CancellationToken;

// Add to struct
pub struct FeatureCityGmlReader {
    // ...
    cancellation_token: CancellationToken,
}

// Update process method
fn process(&mut self, ctx: ExecutorContext, fw: &ProcessorChannelForwarder) -> Result<(), BoxedError> {
    let token = self.cancellation_token.child_token();
    let fw = fw.clone();
    // ...
    pool.spawn(move || {
        if token.is_cancelled() {
            return;
        }
        // ... rest of the processing
    });
    Ok(())
}

// Update finish method to cancel tasks before timeout
fn finish(&self, ctx: NodeContext, _fw: &ProcessorChannelForwarder) -> Result<(), BoxedError> {
    self.cancellation_token.cancel();
    // ... rest of the finish logic
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d443bb and 297cf19.

📒 Files selected for processing (1)
  • engine/runtime/action-processor/src/feature/reader/citygml/processor.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ci-engine / ci

@miseyu miseyu merged commit 589ae4d into main Feb 21, 2025
18 checks passed
@miseyu miseyu deleted the feature/modify-thread-size branch February 21, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant