-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize lease get state for proxy (#27)
- Loading branch information
1 parent
1080d96
commit 74273eb
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package proxy | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
// =============================== | ||
// pool of lease get state | ||
// =============================== | ||
|
||
var leaseGetStatePool = sync.Pool{ | ||
New: func() any { | ||
return &leaseGetState{} | ||
}, | ||
} | ||
|
||
func putLeaseGetState(s *leaseGetState) { | ||
*s = leaseGetState{} | ||
leaseGetStatePool.Put(s) | ||
} | ||
|
||
func getLeaseGetState() *leaseGetState { | ||
return leaseGetStatePool.Get().(*leaseGetState) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package proxy | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLeaseGetStatePool(t *testing.T) { | ||
t.Run("normal", func(t *testing.T) { | ||
s := getLeaseGetState() | ||
assert.Equal(t, &leaseGetState{}, s) | ||
|
||
s.serverID = 123 | ||
|
||
putLeaseGetState(s) | ||
s = getLeaseGetState() | ||
assert.Equal(t, &leaseGetState{}, s) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters