-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
perf: replace /dev/urandom | tr with openssl rand to fix CPU spike in gen_random_string #3887
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -105,10 +105,12 @@ install_base() { | |||
|
|
||||
| gen_random_string() { | ||||
| local length="$1" | ||||
| local random_string=$(LC_ALL=C tr -dc 'a-zA-Z0-9' </dev/urandom | fold -w "$length" | head -n 1) | ||||
| echo "$random_string" | ||||
| # openssl output base64,no need /dev/urandom + tr | ||||
| openssl rand -base64 $(( length * 2 )) \ | ||||
Kookiejarz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| | tr -dc 'a-zA-Z0-9' \ | ||||
| | head -c "$length" | ||||
| } | ||||
|
|
||||
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment contains a Chinese full-width comma (
,) instead of a standard ASCII comma (,). All other comments in this file use ASCII punctuation. The comment is also somewhat cryptic — consider rephrasing to something clearer like:# Use openssl base64 output instead of /dev/urandom to reduce CPU usage.