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

Ensure nginx worker processes respects docker limits #11769

Merged
merged 3 commits into from
Jun 5, 2024

Conversation

felipecrs
Copy link
Contributor

Copy link

netlify bot commented Jun 5, 2024

Deploy Preview for frigate-docs canceled.

Name Link
🔨 Latest commit c2b98f9
🔍 Latest deploy log https://app.netlify.com/sites/frigate-docs/deploys/6660bdc77f391400085c17af

@felipecrs
Copy link
Contributor Author

I tested by starting the devcontainer, then checking the contents of /usr/local/nginx/conf/nginx.conf.

You can limit the cpus in docker-compose.yaml with:

services:
  devcontainer:
    deploy:
      resources:
        limits:
          cpus: '2'

docker/main/Dockerfile Outdated Show resolved Hide resolved
@felipecrs felipecrs requested a review from NickM-27 June 5, 2024 19:34
@felipecrs
Copy link
Contributor Author

felipecrs commented Jun 5, 2024

@NickM-27 made the changes, also tested them.

BTW I just noticed this:

# we need to catch any errors because sed will fail if user has bind mounted a custom nginx file

How about we avoid calling set_worker_processes if the nginx file is mounted? I can do the changes.

@NickM-27
Copy link
Sponsor Collaborator

NickM-27 commented Jun 5, 2024

I think it might be preferable to leave it as is. Changes were made so users shouldn't need to bind mount this file anymore, but in any case probably best to catch any error that occurs so it doesn't stop frigate from starting.

@felipecrs
Copy link
Contributor Author

felipecrs commented Jun 5, 2024

It would be very unexpected to have errors happening at that command though. I have these changes ready:

function set_worker_processes() {
    if mountpoint -q /usr/local/nginx/conf/nginx.conf; then
        echo "[INFO] NGINX configuration is mounted. Skipping worker_processes calculation..." >&2
        return
    fi

    # Capture number of assigned CPUs to calculate worker processes
    local cpus
    cpus=$(get_cpus)
    if [[ "${cpus}" -gt 4 ]]; then
        cpus=4
    fi

    echo "[INFO] Setting NGINX worker_processes to ${cpus}..." >&2
    sed -i "s/worker_processes auto;/worker_processes ${cpus};/" /usr/local/nginx/conf/nginx.conf
}

Let me know in case you change your mind.

@NickM-27 NickM-27 merged commit 53fa64f into blakeblackshear:dev Jun 5, 2024
10 checks passed
@felipecrs felipecrs deleted the fix-cgroups branch June 5, 2024 19:43
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.

None yet

2 participants