refactor: temporarily cache geo data #3294
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Thie PR created some wrappers to temporarily cache the geo data which can reduce the CPU usage.
Tesing
Environment
Stat script
Preparation
With Procpath installed to record the memory usage.
Add
time.Sleep()
in main function for delay the configuration parsing.With the latest geo data downloaded.
Setup the xray config:
Run tests
./xray run -c config.yaml
bash ./stat.sh [before|after]
(using "before", "after" to identify the build before or after the changes).xray
loaded the ruleset, hit Ctrl + C to stop recording and generate the usage image.Result
Records (please download the following images, as these images may not be viewable online):
Proc stat:
Before:
After:
After testing, the changes here can significantly reduce IO reads and reduce the CPU usage duration the configuration loading of this program. There is no very obvious increase in memory usage (in a small number of tests, a peak memory usage of "75MB" can be observed.