Skip to content

feature(core): implement core.sleep#2397

Merged
moonming merged 9 commits into
apache:masterfrom
dabue:feat_sleep
Oct 19, 2020
Merged

feature(core): implement core.sleep#2397
moonming merged 9 commits into
apache:masterfrom
dabue:feat_sleep

Conversation

@dabue

@dabue dabue commented Oct 12, 2020

Copy link
Copy Markdown
Contributor

fix #2170

Use a small time interval (such as 1s) to complete a relatively long sleep behavior, so that the worker process can be shut down gracefully.

local max_sleep_interval = 1

local function sleep(sec)
    if sec <= max_sleep_interval then
        ngx_sleep(sec)
        return
    end
    ngx_sleep(max_sleep_interval)
    if exiting() then
        return
    end
    sec = sec - max_sleep_interval
    sleep(sec)
end

@membphis membphis left a comment

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.

LGTM, except for minor code style

Comment thread apisix/core/utils.lua Outdated
Comment thread apisix/core/utils.lua Outdated
Comment thread apisix/core/utils.lua Outdated
@moonming

Copy link
Copy Markdown
Member

Is there a long sleep in the project?

@moonming

Copy link
Copy Markdown
Member

This change seems to be of little use to the current code

@dabue

dabue commented Oct 13, 2020

Copy link
Copy Markdown
Contributor Author

This change seems to be of little use to the current code

Among the current code, it really only work better when the worker process being shut down at the time of triggering request limiting and delaying processing. And we can keep it as a better way to sleep for the future usage scenarios.

@membphis

membphis commented Oct 17, 2020

Copy link
Copy Markdown
Member

I think this feature is useful.

When the APISIX instance restarts, we need to exit sleep as soon as possible.
Then the Nginx process can be gracefully shut down immediately, and free the system resources asap.

@moonming
moonming merged commit 943be09 into apache:master Oct 19, 2020
@membphis

Copy link
Copy Markdown
Member

@dabue many thx

@moonming moonming added this to the 2.0 milestone Oct 19, 2020
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.

feature(core): implement core.sleep

4 participants