Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b2f6e7d0
Commit
b2f6e7d0
authored
Jan 27, 2016
by
Filip Grzadkowski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20209 from fgrzadkowski/master
Speed up UUID generation.
parents
729a76f7
a5a23940
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
11 deletions
+10
-11
uuid.go
pkg/util/uuid.go
+10
-11
No files found.
pkg/util/uuid.go
View file @
b2f6e7d0
...
@@ -18,26 +18,25 @@ package util
...
@@ -18,26 +18,25 @@ package util
import
(
import
(
"sync"
"sync"
"time"
"github.com/pborman/uuid"
"github.com/pborman/uuid"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/types"
)
)
var
uuidLock
sync
.
Mutex
var
uuidLock
sync
.
Mutex
var
lastUUID
uuid
.
UUID
/**
* The UUID package is naive and can generate identical UUIDs if the time interval is quick enough.
* Block subsequent UUIDs for 200 Nanoseconds, the UUID uses 100 ns increments, we block for 200 to be safe
* Blocks in a go routine, so that the caller doesn't have to wait.
* TODO: save old unused UUIDs so that no one has to block.
*/
func
NewUUID
()
types
.
UID
{
func
NewUUID
()
types
.
UID
{
uuidLock
.
Lock
()
uuidLock
.
Lock
()
defer
uuidLock
.
Unlock
()
result
:=
uuid
.
NewUUID
()
result
:=
uuid
.
NewUUID
()
go
func
()
{
// The UUID package is naive and can generate identical UUIDs if the
time
.
Sleep
(
200
*
time
.
Nanosecond
)
// time interval is quick enough.
uuidLock
.
Unlock
()
// The UUID uses 100 ns increments so it's short enough to actively
}()
// wait for a new value.
for
uuid
.
Equal
(
lastUUID
,
result
)
==
true
{
result
=
uuid
.
NewUUID
()
}
lastUUID
=
result
return
types
.
UID
(
result
.
String
())
return
types
.
UID
(
result
.
String
())
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment