Skip to content

Commit

Permalink
dir optimize
Browse files Browse the repository at this point in the history
Signed-off-by: kl7sn <mex7.0828@gmail.com>
  • Loading branch information
kl7sn committed Jul 18, 2023
1 parent f7e299e commit 70eab8a
Show file tree
Hide file tree
Showing 26 changed files with 307 additions and 189 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@

.idea/*

logs
logs
test
3 changes: 3 additions & 0 deletions preempt/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/gotomicro/cetus/preempt

go 1.20
104 changes: 104 additions & 0 deletions test/syncmap/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package main

import (
"fmt"
"sync"
"time"
)

var ConnectionPool = sync.Pool{
New: func() interface{} {
return &Connection{}
},
}

func GetConn() *Connection {
cli := ConnectionPool.Get().(*Connection)
return cli
}

func PutConn(cli *Connection) {
cli.reset()
ConnectionPool.Put(cli) // 放回连接池
}

var redisOpZRangeCost = time.Millisecond * 1000
var redisOpDeleteCost = time.Millisecond * 100

var clients = sync.Map{}

// Connection Operator structure
type Connection struct {
Id int
Uid int
}

func main() {
go clear()

fmt.Println("....add....", time.Now().Unix())
for j := 1; j < 10000; j++ {
connect(j, j)
}
fmt.Println("....delete....", time.Now().Unix())

go func() {
for j := 1; j < 10000; j++ {
disconnect(get(j))
}
}()
select {}
}

func connect(id, uid int) {
c := GetConn()
c.Id = id
c.Uid = uid
clients.Store(c.Id, c)
}

func disconnect(c *Connection) {
if c == nil {
return
}
clients.Delete(c.Id)
// redis 操作
time.Sleep(redisOpDeleteCost)
PutConn(c)
}

func get(id int) *Connection {
val, ok := clients.Load(id)
if ok {
return val.(*Connection)
}
return nil
}

func clear() {
for {
fmt.Println("....clear....", time.Now().Unix())

clients.Range(func(_, v interface{}) bool {
client := v.(*Connection)
zRangeOp(client.Id, client.Uid)
return true
})
time.Sleep(time.Second * 3)
}
}

func zRangeOp(id, uid int) {
time.Sleep(redisOpZRangeCost)

if uid == 0 {
fmt.Println(id, uid, "..............Fatal Error..................................................", time.Now().Unix())
}
fmt.Println(id, uid)

}

func (cli *Connection) reset() {
cli.Uid = 0
cli.Id = 0
}
File renamed without changes.
2 changes: 1 addition & 1 deletion kauth/base.go → xauth/base.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kauth
package xauth

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion kauth/base_test.go → xauth/base_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kauth
package xauth

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion kauth/errors.go → xauth/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kauth
package xauth

type Error struct {
s string
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion kauth/generic.go → xauth/generic.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kauth
package xauth

import (
"encoding/base64"
Expand Down
2 changes: 1 addition & 1 deletion kauth/github.go → xauth/github.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kauth
package xauth

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion kauth/gitlab.go → xauth/gitlab.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kauth
package xauth

import (
"encoding/json"
Expand Down
80 changes: 40 additions & 40 deletions go.mod → xauth/go.mod
Original file line number Diff line number Diff line change
@@ -1,76 +1,73 @@
module github.com/gotomicro/cetus
module github.com/gotomicro/cetus/xauth

go 1.18
go 1.20

require (
github.com/ego-component/eredis v1.0.3
github.com/gin-gonic/gin v1.7.7
github.com/go-redis/redis/v8 v8.11.5
github.com/googollee/go-socket.io v1.6.2
github.com/gotomicro/ego v1.1.3
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
github.com/mailru/easyjson v0.7.7
github.com/segmentio/kafka-go v0.4.31
github.com/spf13/cast v1.5.0
go.uber.org/zap v1.21.0
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
google.golang.org/grpc v1.47.0
github.com/gin-gonic/gin v1.9.1
github.com/gotomicro/cetus v0.1.3
github.com/gotomicro/ego v1.1.12
github.com/spf13/cast v1.5.1
go.uber.org/zap v1.24.0
golang.org/x/oauth2 v0.10.0
)

require (
github.com/BurntSushi/toml v1.1.0 // indirect
github.com/RaMin0/gin-health-check v0.0.0-20180807004848-a677317b3f01 // indirect
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
github.com/alibaba/sentinel-golang v1.0.3 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/felixge/fgprof v0.9.2 // indirect
github.com/fasthttp/websocket v1.5.2 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.9.0 // indirect
github.com/go-redis/redis/extra/rediscmd/v8 v8.11.5 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gomodule/redigo v1.8.4 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/go-resty/resty/v2 v2.7.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.11.3 // indirect
github.com/google/pprof v0.0.0-20220608213341-c488b8fa1db3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gotomicro/logrotate v0.0.0-20211108034117-46d53eedc960 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.14.2 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pierrec/lz4/v4 v4.1.14 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.34.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/shirou/gopsutil/v3 v3.21.6 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.6 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/ugorji/go/codec v1.2.6 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.45.0 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.7.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.7.0 // indirect
Expand All @@ -82,14 +79,17 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/automaxprocs v1.5.1 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3 // indirect
google.golang.org/protobuf v1.28.0 // indirect
google.golang.org/grpc v1.47.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 70eab8a

Please sign in to comment.