[PR #1116] [CLOSED] Repeat ToStringSlice #1892

Closed
opened 2025-12-29 03:18:39 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/1116
Author: @QZAiXH
Created: 1/5/2023
Status: Closed

Base: mainHead: optimize_cpu


📝 Commits (5)

  • bdca7d6 reflect.DeepEqual is a value copy that causes golang to continuously allocate memory
  • 8b2f4fb reflect.DeepEqual is a value copy that causes golang to continuously allocate memory
  • 1629e1a Merge remote-tracking branch 'origin/optimize_cpu' into optimize_cpu
  • 2e6dda0 Merge branch 'main' into optimize_cpu
  • 5f88347 ToStringSlice will lead to high CPU usage, early conversion can reduce cpu usage

📊 Changes

1 file changed (+9 additions, -7 deletions)

View changed files

📝 machine.go (+9 -7)

📄 Description

  • read the CONTRIBUTING guidelines
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md

I've been watching the cpu situation for the past few days, and I found that the cpu occasionally suddenly rises to 500%, so I used pprof to check and found that ToStringSlice causes the cpu to rise.

After optimizing it, the cpu is still rising occasionally, but not very much.

The final solution should be to use the cache to store the machine information for comparison, and modify the database data and cache information only when there are changes. I'm not familiar with it, so I haven't made the appropriate changes yet.

before_optimization

after_optimization


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/juanfont/headscale/pull/1116 **Author:** [@QZAiXH](https://github.com/QZAiXH) **Created:** 1/5/2023 **Status:** ❌ Closed **Base:** `main` ← **Head:** `optimize_cpu` --- ### 📝 Commits (5) - [`bdca7d6`](https://github.com/juanfont/headscale/commit/bdca7d626d6ad13584e98cba7730f21b6afb578c) reflect.DeepEqual is a value copy that causes golang to continuously allocate memory - [`8b2f4fb`](https://github.com/juanfont/headscale/commit/8b2f4fb613e66f2015d4aec9d4f2c0e6555a1b79) reflect.DeepEqual is a value copy that causes golang to continuously allocate memory - [`1629e1a`](https://github.com/juanfont/headscale/commit/1629e1a07805de788bdb1b4036021e7b2200cc6e) Merge remote-tracking branch 'origin/optimize_cpu' into optimize_cpu - [`2e6dda0`](https://github.com/juanfont/headscale/commit/2e6dda0e90f69aa7b82142d37e3f441a0f995f8c) Merge branch 'main' into optimize_cpu - [`5f88347`](https://github.com/juanfont/headscale/commit/5f8834798d4606fb004fc6fe518ec03308959405) ToStringSlice will lead to high CPU usage, early conversion can reduce cpu usage ### 📊 Changes **1 file changed** (+9 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `machine.go` (+9 -7) </details> ### 📄 Description <!-- Please tick if the following things apply. You… --> - [x] read the [CONTRIBUTING guidelines](README.md#contributing) - [ ] raised a GitHub issue or discussed it on the projects chat beforehand - [ ] added unit tests - [ ] added integration tests - [ ] updated documentation if needed - [ ] updated CHANGELOG.md <!-- If applicable, please reference the issue using `Fixes #XXX` and add tests to cover your new code. --> I've been watching the cpu situation for the past few days, and I found that the cpu occasionally suddenly rises to 500%, so I used pprof to check and found that ToStringSlice causes the cpu to rise. After optimizing it, the cpu is still rising occasionally, but not very much. The final solution should be to use the cache to store the machine information for comparison, and modify the database data and cache information only when there are changes. I'm not familiar with it, so I haven't made the appropriate changes yet. ![before_optimization](https://user-images.githubusercontent.com/23068780/210695313-54af7475-d527-4274-b33a-50838c44ed98.svg) ![after_optimization](https://user-images.githubusercontent.com/23068780/210695393-754f2a55-6894-42ac-8ecc-6294109e2f19.svg) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 03:18:39 +01:00
adam closed this issue 2025-12-29 03:18:39 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#1892