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

Implement 24-hour check for apt cache updates to reduce network-load … #746

Closed
wants to merge 2 commits into from

Conversation

FelmeAn
Copy link

@FelmeAn FelmeAn commented Aug 10, 2024

…and improve running times

Proposed changes

General information

This commit introduces a time-based check to ensure the apt-get cache is updated only once every 24 hours, optimizing resource usage and reducing network load.

Why:
Many Linux servers, including those within our company, utilize unattended upgrades that automatically update the package database. Limiting cache updates to once every 24 hours helps to minimize unnecessary load on our custom repo mirror/apt-cacher, especially when other services may have already performed an update.

Technical Details:
Modification Time Check: The script checks the modification timestamp of /var/cache/apt/pkgcache.bin to determine when the last update occurred. It calculates the time elapsed since that update using the timestamp.

Time Difference Calculation: If more than 24 hours (86400 seconds) have passed since the last update, the script triggers an apt-get update, ensuring updates are performed only when necessary.

Benefits:
Server Load Reduction: By throttling updates, we reduce the load on package servers, apt-cacher proxies, or custom mirrors, preventing server strain and ensuring better availability of resources.

Resource Efficiency: This approach conserves bandwidth and processing power by avoiding unnecessary updates, particularly in stable environments where frequent updates provide minimal benefit.

Reduced Script Run Time: By skipping unnecessary updates, the script executes more quickly.

…and improve running times

This commit introduces a time-based check to ensure the apt-get cache is updated only once every 24 hours, optimizing resource usage and reducing network load.

Why:
Many Linux servers, including those within our company, utilize unattended upgrades that automatically update the package database. Limiting cache updates to once every 24 hours helps to minimize unnecessary load on our custom repo mirror/apt-cacher, especially when other services may have already performed an update.

Technical Details:
Modification Time Check: The script checks the modification timestamp of /var/cache/apt/pkgcache.bin to determine when the last update occurred. It calculates the time elapsed since that update using the timestamp.

Time Difference Calculation: If more than 24 hours (86400 seconds) have passed since the last update, the script triggers an apt-get update, ensuring updates are performed only when necessary.

Benefits:
Server Load Reduction: By throttling updates, we reduce the load on package servers, apt-cacher proxies, or custom mirrors, preventing server strain and ensuring better availability of resources.

Resource Efficiency: This approach conserves bandwidth and processing power by avoiding unnecessary updates, particularly in stable environments where frequent updates provide minimal benefit.

Reduced Script Run Time: By skipping unnecessary updates, the script executes more quickly.
Copy link

github-actions bot commented Aug 10, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@FelmeAn
Copy link
Author

FelmeAn commented Aug 10, 2024

I have read the CLA Document and I hereby sign the CLA or my organization already has a signed CLA.

@Yogibaer75
Copy link
Contributor

What if someone want's to check every hour for new updates?
I think you should set the cache interval for this check to an value suited for your environment like 24 hours.

@FelmeAn
Copy link
Author

FelmeAn commented Aug 11, 2024

We can set it to update every hour, but in my opinion, it's not necessary to refresh the cache on every run.

@Yogibaer75
Copy link
Contributor

Yogibaer75 commented Aug 13, 2024

it's not necessary to refresh the cache on every run.

The plugin should be configured to run only every X hours.
In my systems it runs one or two times per day and on this run it should really check for updates not only show a cached value.

@FelmeAn
Copy link
Author

FelmeAn commented Aug 21, 2024

We have running the check not every 1 nor 5 minutes, but a few times a day, but we can set the limit to 6 hours so if someone has forgotten to decrease the interval of the check, it won't update every X Seconds/Minutes.

@gurubert
Copy link
Contributor

gurubert commented Oct 1, 2024

This PR is not necessary as you already can achieve its goal with asynchronous execution of the plugin.

@FelmeAn FelmeAn closed this Oct 1, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Oct 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants