Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cache and throttling for
certificates
, keychain_acls
, and `…
…keychain_items` tables. (osquery#8192) Fixes osquery#7780 Related issue: fleetdm/fleet#13065 Adding a cache for macOS keychain file accesses. The cache checks whether a keychain file has been modified by comparing the file's SHA256 hash. If the file has been modified, the cache also checks whether the file has been accessed recently. If it has been accessed within the configured interval, the old cached results are returned. The cache works independently for each table. This means that multiple tables can access the keychain files within the interval, but each one of them can only do so once. The following feature flags have been added: ``` --keychain_access_cache Use a cache for keychain accesses (default true) --keychain_access_interval VALUE Minimum minutes required between keychain accesses. Keychain cache must be enabled to use ``` Default `keychain_access_interval` is 5 minutes. Old table results exactly match new table results when ordered by primary key. Performance results for `certificates` for 10 rounds (old vs new): ``` U:1 C:0 M:3 F:0 D:0 manual: utilization: 13.940000000000001 cpu_time: 0.14197365480000002 memory: 35979264.0 fds: 4.0 duration: 0.5259468078613281 U:1 C:0 M:3 F:0 D:0 manual: utilization: 13.236666666666668 cpu_time: 0.13929492440000002 memory: 35386163.2 fds: 4.0 duration: 0.5783782720565795 ``` Performance results for `certificates` for 10 counts (new is faster and less memory due to cache): ``` U:2 C:1 M:3 F:0 D:2 manual: utilization: 44.29999999999999 cpu_time: 0.669130928 memory: 50331648.0 fds: 4.0 duration: 1.5303008556365967 U:2 C:1 M:3 F:0 D:2 manual: utilization: 28.366666666666664 cpu_time: 0.42878788 memory: 40534016.0 fds: 4.0 duration: 1.0357069969177246 ``` Performance results for `keychain_acls` for 10 rounds (old vs new): ``` U:1 C:0 M:3 F:0 D:0 manual: utilization: 10.57 cpu_time: 0.10779758619999999 memory: 29374873.6 fds: 4.0 duration: 0.5254422664642334 U:1 C:0 M:3 F:0 D:0 manual: utilization: 11.366666666666669 cpu_time: 0.1201387166 memory: 29420748.8 fds: 4.0 duration: 0.5800627708435059 ``` Performance results for `keychain_acls` for 10 counts (new is faster and less memory due to cache): ``` U:2 C:1 M:3 F:0 D:2 manual: utilization: 22.059999999999995 cpu_time: 0.557502384 memory: 77463552.0 fds: 4.0 duration: 2.0405030250549316 U:2 C:1 M:3 F:0 D:2 manual: utilization: 26.733333333333334 cpu_time: 0.405785928 memory: 36782080.0 fds: 4.0 duration: 1.0386288166046143 ``` Performance results for `keychain_items` for 10 rounds (old vs new). **New performance is better.** This is likely because the new code only opens each keychain file once, while old code opened each keychain file multiple times -- once for each keychain item type (password, certificate, etc.) ``` U:2 C:1 M:3 F:0 D:1 manual: utilization: 30.510833333333334 cpu_time: 0.45226203760000006 memory: 29961420.8 fds: 4.0 duration: 0.9804916620254517 U:2 C:0 M:3 F:0 D:0 manual: utilization: 20.805 cpu_time: 0.2112246234 memory: 26363494.4 fds: 4.0 duration: 0.5286885976791382 ``` Performance results for `keychain_items` for 10 counts (new is way faster and less memory): ``` U:3 C:2 M:3 F:0 D:3 manual: utilization: 78.25999999999999 cpu_time: 3.946559488 memory: 41320448.0 fds: 4.0 duration: 4.564563989639282 U:2 C:1 M:3 F:0 D:2 manual: utilization: 25.474999999999998 cpu_time: 0.511153552 memory: 33996800.0 fds: 4.0 duration: 1.5302011966705322 ```
- Loading branch information