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

using exp/rand to reduce memory usage #39

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions circuitbreaker/sre/sre.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package sre

import (
"math"
"math/rand"
"sync"
"sync/atomic"
"time"

"github.com/go-kratos/aegis/circuitbreaker"
"github.com/go-kratos/aegis/internal/window"
"golang.org/x/exp/rand"
)

// Option is sre breaker option function.
Expand Down Expand Up @@ -100,7 +100,7 @@ func NewBreaker(opts ...Option) circuitbreaker.CircuitBreaker {
stat := window.NewRollingCounter(counterOpts)
return &Breaker{
stat: stat,
r: rand.New(rand.NewSource(time.Now().UnixNano())),
r: rand.New(rand.NewSource(uint64(time.Now().UnixNano()))),
request: opt.request,
k: 1 / opt.success,
state: StateClosed,
Expand Down
2 changes: 1 addition & 1 deletion circuitbreaker/sre/sre_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package sre

import (
"math"
"math/rand"
"testing"
"time"

"github.com/go-kratos/aegis/internal/window"
"github.com/stretchr/testify/assert"
"golang.org/x/exp/rand"
)

func getSREBreaker() *Breaker {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/shirou/gopsutil/v3 v3.23.2
github.com/stretchr/testify v1.8.2
github.com/twmb/murmur3 v1.1.6
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ github.com/twmb/murmur3 v1.1.6 h1:mqrRot1BRxm+Yct+vavLMou2/iJt0tNVTTC0QoIjaZg=
github.com/twmb/murmur3 v1.1.6/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
2 changes: 1 addition & 1 deletion hotkey/hotkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package hotkey

import (
"fmt"
"math/rand"
"strconv"
"testing"
"time"

"github.com/stretchr/testify/assert"
"golang.org/x/exp/rand"
)

func benchmarkHotkey(b *testing.B, autoCache bool, writePercent float64, whilelist ...*CacheRuleConfig) {
Expand Down
3 changes: 2 additions & 1 deletion internal/consistent/consistent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package consistent
import (
"bufio"
"encoding/base64"
"math/rand"
"os"
"runtime"
"sort"
Expand All @@ -16,6 +15,8 @@ import (
"testing"
"testing/quick"
"time"

"golang.org/x/exp/rand"
)

type member string
Expand Down
2 changes: 1 addition & 1 deletion ratelimit/bbr/bbr_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bbr

import (
"math/rand"
"sync"
"sync/atomic"
"testing"
Expand All @@ -10,6 +9,7 @@ import (
"github.com/go-kratos/aegis/internal/window"
"github.com/go-kratos/aegis/ratelimit"
"github.com/stretchr/testify/assert"
"golang.org/x/exp/rand"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion subset/subset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package subset
import (
"encoding/json"
"io/ioutil"
"math/rand"
"testing"

"github.com/go-kratos/aegis/internal/consistent"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"golang.org/x/exp/rand"
)

type member string
Expand Down
3 changes: 1 addition & 2 deletions topk/heavykeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ package topk

import (
"math"
"math/rand"

"github.com/go-kratos/aegis/internal/minheap"

"github.com/twmb/murmur3"
"golang.org/x/exp/rand"
)

const LOOKUP_TABLE = 256
Expand Down
2 changes: 1 addition & 1 deletion topk/heavykeeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package topk

import (
"math"
"math/rand"
"strconv"
"testing"
"time"

"github.com/stretchr/testify/assert"
"golang.org/x/exp/rand"
)

func TestTopkList(t *testing.T) {
Expand Down