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

Slow log parse performance improvement for splitByColon #54538

Closed
yibin87 opened this issue Jul 10, 2024 · 11 comments · Fixed by #54630
Closed

Slow log parse performance improvement for splitByColon #54538

yibin87 opened this issue Jul 10, 2024 · 11 comments · Fixed by #54630
Assignees
Labels
affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. severity/major type/bug The issue is confirmed as a bug.

Comments

@yibin87
Copy link
Contributor

yibin87 commented Jul 10, 2024

Enhancement

Do cpu profile for query like:

SELECT
  Digest,
  Query,
  Conn_ID,
  (UNIX_TIMESTAMP(Time) + 0E0) AS timestamp,
  Query_time,
  Mem_max,
  Process_keys
FROM
  `INFORMATION_SCHEMA`.`CLUSTER_SLOW_QUERY`
WHERE
  Time BETWEEN FROM_UNIXTIME(?)
  AND FROM_UNIXTIME(?)
ORDER BY
  Query_time DESC
LIMIT 100;

Find the splitByColon takes about 80% cpu times:
img_v3_02cl_7c4b6024-a3b3-4168-b5c4-86858cb0605g

The implementation uses regexp to parse key: value strings:

// kvSplitRegex: it was just for split "field: value field: value..."
var kvSplitRegex = regexp.MustCompile(`\w+: `)
// splitByColon split a line like "field: value field: value..."
func splitByColon(line string) (fields []string, values []string) {
matches := kvSplitRegex.FindAllStringIndex(line, -1)

However, in most cases, we can just go through the string, and take string before colon as key, string after colon as value, which seems can improve performance significantly.

@yibin87 yibin87 added the type/enhancement The issue or PR belongs to an enhancement. label Jul 10, 2024
@yibin87 yibin87 changed the title Slow log parse performance Slow log parse performance improvement for splitByColon Jul 10, 2024
@yibin87
Copy link
Contributor Author

yibin87 commented Jul 10, 2024

/assign @yibin87

@yibin87
Copy link
Contributor Author

yibin87 commented Sep 2, 2024

/remove-label enhancement

Copy link

ti-chi-bot bot commented Sep 2, 2024

@yibin87: The label(s) enhancement cannot be applied. These labels are supported: fuzz/sqlancer, challenge-program, compatibility-breaker, first-time-contributor, contribution, good first issue, correctness, duplicate, proposal, security, ok-to-test, needs-ok-to-test, needs-more-info, needs-cherry-pick-release-5.4, needs-cherry-pick-release-6.1, needs-cherry-pick-release-6.5, needs-cherry-pick-release-7.1, needs-cherry-pick-release-7.5, needs-cherry-pick-release-8.1, needs-cherry-pick-release-8.3, affects-5.4, affects-6.1, affects-6.5, affects-7.1, affects-7.5, affects-8.1, affects-8.3, may-affects-5.4, may-affects-6.1, may-affects-6.5, may-affects-7.1, may-affects-7.5, may-affects-8.1.

In response to this:

/remove-label enhancement

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@windtalker windtalker added the type/bug The issue is confirmed as a bug. label Sep 2, 2024
@yibin87
Copy link
Contributor Author

yibin87 commented Sep 2, 2024

/type bug

@windtalker windtalker removed the type/enhancement The issue or PR belongs to an enhancement. label Sep 2, 2024
@yibin87
Copy link
Contributor Author

yibin87 commented Sep 2, 2024

/label affects-6.5

@ti-chi-bot ti-chi-bot bot added the affects-6.5 This bug affects the 6.5.x(LTS) versions. label Sep 2, 2024
@yibin87
Copy link
Contributor Author

yibin87 commented Sep 2, 2024

/severity major

@yibin87
Copy link
Contributor Author

yibin87 commented Sep 2, 2024

/label affects-8.1

@ti-chi-bot ti-chi-bot bot added affects-8.1 This bug affects the 8.1.x(LTS) versions. and removed may-affects-8.1 labels Sep 2, 2024
@yibin87
Copy link
Contributor Author

yibin87 commented Sep 2, 2024

/label affects-7.5

@ti-chi-bot ti-chi-bot bot added affects-7.5 This bug affects the 7.5.x(LTS) versions. and removed may-affects-7.5 labels Sep 2, 2024
@yibin87
Copy link
Contributor Author

yibin87 commented Sep 2, 2024

/label affects-7.1

@ti-chi-bot ti-chi-bot bot added the affects-7.1 This bug affects the 7.1.x(LTS) versions. label Sep 2, 2024
@yibin87
Copy link
Contributor Author

yibin87 commented Sep 2, 2024

/label affects-6.1

@ti-chi-bot ti-chi-bot bot added affects-6.1 This bug affects the 6.1.x(LTS) versions. and removed may-affects-6.1 labels Sep 2, 2024
@yibin87
Copy link
Contributor Author

yibin87 commented Sep 2, 2024

/remove-label may-affects-5.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. severity/major type/bug The issue is confirmed as a bug.
Projects
None yet
2 participants