Comments (7)
Make it easy for me. Send a pointer to the Redis related code and whatever "raw" is.
from redigo.
op code:
package models
import (
"errors"
"strconv"
"time"
"log"
"github.com/garyburd/redigo/redis"
)
var (
Objects map[string]*Object
RedisPool *redis.Pool
server = "127.0.0.1:6379"
objectHashName = "object"
)
type Object struct {
ObjectId string
Score int64
PlayerName string
}
func init() {
Objects = make(map[string]*Object)
Objects["hjkhsbnmn123"] = &Object{"hjkhsbnmn123", 100, "astaxie"}
Objects["mjjkxsxsaa23"] = &Object{"mjjkxsxsaa23", 101, "someone"}
RedisPool = &redis.Pool{
MaxIdle: 5,
MaxActive: 10000,
IdleTimeout: time.Duration(5) * time.Second,
TestOnBorrow: func(c redis.Conn, t time.Time) error {
_, err := c.Do("PING")
return err
},
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", server)
if err != nil {
log.Printf("Dail redis server %s %v", server, err)
return nil, err
}
if _, err := c.Do("PING"); err != nil {
c.Close()
return nil, err
}
return c, err
},
}
}
type Object struct {
ObjectId string
Score int64
PlayerName string
}
//this the raw
func GetAll() map[string]*Object {
return Objects
}
//get data from redis hash list
func GetObject() (object *Object, err error) {
conn := GetRedis()
defer conn.Close()
object = new(Object)
reply, err := redis.Values(conn.Do("HGETALL", objectHashName))
if nil != err {
log.Printf("set object to redis hash get error %s", err)
return
}
err = redis.ScanStruct(reply, object)
return
}
func GetRedis() redis.Conn {
// c, err := redis.Dial("tcp", server)
// if err != nil {
// log.Printf("Dail master redis server %s %v", server, err)
// return nil
// }
// return c
return RedisPool.Get()
}
beego original method will run models.GetAll()
$ wrk -t12 -c400 -d30s http://127.0.0.1:8081/object
Running 30s test @ http://127.0.0.1:8081/object
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.39s 375.09ms 1.65s 92.90%
Req/Sec 1.35k 2.56k 14.22k 88.50%
479750 requests in 30.01s, 161.05MB read
Requests/sec: 15987.51
Transfer/sec: 5.37MB
get data from redis hash list use redigo will run models.GetObject()
$ wrk -t12 -c400 -d30s http://127.0.0.1:8081/get
Running 30s test @ http://127.0.0.1:8081/get
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 87.87ms 88.84ms 740.17ms 93.32%
Req/Sec 417.59 129.96 1.55k 80.07%
149451 requests in 30.00s, 33.35MB read
Requests/sec: 4981.43
Transfer/sec: 1.11MB
from redigo.
Because GetAll and GetObject do different things as evidenced by the return values, I don't understand what it is you are trying to compare.
GetAll is expected to be faster GetObject. GetAll simply returns a value. The GetAll function is probably inlined. GetObject fetches a value from the Redis server running in another process.
Any Redis client will be slow compared to a simple inlined function. The use of any database server over the network will be slow compared to a simple inlined function.
from redigo.
But Is decrease too much, only have Requests/sec: 4981.43. Use redis GET command the same thought output. So small throughput I can't run redigo code in my product machine.
from redigo.
Removing the PING will improve performance.
from redigo.
You mean remove PING in Dial? PING in TestOnBorrow can be remove?
from redigo.
I am referring to the PING in TestOnBorrow.
Based on the snippet of code pasted here, I would not PING on every call to TestOnBorrow.
from redigo.
Related Issues (20)
- Act subscribe immediately without receive message HOT 1
- use pipline send got ERR wrong number of arguments for 'set' command HOT 6
- Why is v1.8.9 newer than v2.0.0 ? HOT 1
- Could you remove v2.0.0 tag HOT 2
- pool can support FIFO? HOT 3
- Potential goroutine leak in TestDialTLSHandshakeTimeout HOT 1
- Expose DialOptions used to create the connection to support instrumentation/tracing features HOT 10
- dial-tcp-connect-cannot-assign-requested-address? HOT 1
- Not able to connect when Redis Password contains"/" HOT 2
- Wait pool timeout? HOT 2
- The order of pipeline send commands is not fixed HOT 3
- buffio.Write may write less bytes than requested HOT 1
- pubSubConn.Receive() is insufficient HOT 1
- Increase tail latencies when migrated service to arm64 architecture HOT 1
- Vulnerability of dependency "gopkg.in/yaml.v3"
- Support for log/slog HOT 11
- v2 Proposal HOT 2
- Compilation fails for v1.9.1 in go1.16 environment HOT 1
- Error using HSET on 1.6.2 HOT 1
- Close TLS connection if handshake timeout HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redigo.