Skip to content

Fix:RunAllTasks should be implemented by passing the number of tasks - #14542

Closed
dreamlike-ocean wants to merge 1 commit into
netty:4.2from
dreamlike-ocean:feature-fix-runAlltask
Closed

dreamlike-ocean wants to merge 1 commit into
netty:4.2from
dreamlike-ocean:feature-fix-runAlltask

Conversation

@dreamlike-ocean

Copy link
Copy Markdown
Member

Motivation:

RunAllTasks should be implemented by passing the number of tasks to run, rather than using a timeout

Modification:

Add an override method to handle running all tasks correctly

Result:

#14165

@franz1981

Copy link
Copy Markdown
Contributor

RunAllTasks should be implemented by passing the number of tasks to run, rather than using a timeout

duration of such tasks is not known, some could be long, other shorts; why you want to use the number of tasks?

@dreamlike-ocean

dreamlike-ocean commented Dec 6, 2024 •

Copy link
Copy Markdown
Member Author

RunAllTasks should be implemented by passing the number of tasks to run, rather than using a timeout

duration of such tasks is not known, some could be long, other shorts; why you want to use the number of tasks?

I have checked the code of SingleThreadIoEventLoop::run.
If the code uses a timeout, the default value might not be enough. Therefore, I believe the intention of the original code is to specify the number of tasks to run.

Do you have any better ideas

    @Override
    protected void run() {
        assert inEventLoop();
        do {
            runIo();
            if (isShuttingDown()) {
                ioHandler.prepareToDestroy();
            }
            runAllTasks(maxTasksPerRun);

            // We should continue with our loop until we either confirmed a shutdown or we can suspend it.
        } while (!confirmShutdown() && !canSuspend());
    }
protected static final int DEFAULT_MAX_TASKS_PER_RUN = Math.max(1,
            SystemPropertyUtil.getInt("io.netty.eventLoop.maxTaskPerRun", 1024 * 4))

@normanmaurer

Copy link
Copy Markdown
Member

@dreamlike-ocean I think you are correct here.

runTasks ++;

task = pollTask();
if (task == null || runTasks >= maxTasksPerRun) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (task == null || runTasks >= maxTasksPerRun) {
if (task == null || runTasks == maxTasksPerRun) {

*
* @return {@code true} if at least one task was run.
*/
protected boolean runAllTasks(int maxTasksPerRun) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's rename it to something like this and call it from SingleThreadIoEventLoop.

Suggested change
protected boolean runAllTasks(int maxTasksPerRun) {
protected boolean runAllTasksWithLimit(int maxTasksPerRun) {

@normanmaurer

Copy link
Copy Markdown
Member

Or wait... I think we should better fix it by using a timeout like @franz1981 suggested. Will do a PR shortly

@normanmaurer

Copy link
Copy Markdown
Member

Closed in favor of #14557

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants