forked from mirror/ledisdb
add conn keep alive check and bug fix
This commit is contained in:
parent
89c58e45ca
commit
b9b60f19ad
|
@ -111,8 +111,9 @@ type Config struct {
|
|||
|
||||
Snapshot SnapshotConfig `toml:"snapshot"`
|
||||
|
||||
ConnReadBufferSize int `toml:"conn_read_buffer_size"`
|
||||
ConnWriteBufferSize int `toml:"conn_write_buffer_size"`
|
||||
ConnReadBufferSize int `toml:"conn_read_buffer_size"`
|
||||
ConnWriteBufferSize int `toml:"conn_write_buffer_size"`
|
||||
ConnKeepaliveInterval int `toml:"conn_keepavlie_interval"`
|
||||
|
||||
TTLCheckInterval int `toml:"ttl_check_interval"`
|
||||
}
|
||||
|
|
|
@ -44,9 +44,14 @@ db_sync_commit = 0
|
|||
use_replication = false
|
||||
|
||||
# set connection buffer, you can increase them appropriately
|
||||
# more size, more memory used
|
||||
conn_read_buffer_size = 10240
|
||||
conn_write_buffer_size = 10240
|
||||
|
||||
# if connection receives no data after n seconds, it may be dead, close
|
||||
# 0 to disable and not check
|
||||
conn_keepavlie_interval = 0
|
||||
|
||||
# checking TTL (time to live) data every n seconds
|
||||
# if you set big, the expired data may not be deleted immediately
|
||||
ttl_check_interval = 1
|
||||
|
|
|
@ -44,9 +44,14 @@ db_sync_commit = 0
|
|||
use_replication = false
|
||||
|
||||
# set connection buffer, you can increase them appropriately
|
||||
# more size, more memory used
|
||||
conn_read_buffer_size = 10240
|
||||
conn_write_buffer_size = 10240
|
||||
|
||||
# if connection receives no data after n seconds, it may be dead, close
|
||||
# 0 to disable and not check
|
||||
conn_keepavlie_interval = 0
|
||||
|
||||
# checking TTL (time to live) data every n seconds
|
||||
# if you set big, the expired data may not be deleted immediately
|
||||
ttl_check_interval = 1
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var errReadRequest = errors.New("invalid request protocol")
|
||||
|
@ -81,8 +82,13 @@ func (c *respClient) run() {
|
|||
c.app.removeSlave(c.client, handleQuit)
|
||||
}()
|
||||
|
||||
kc := time.Duration(c.app.cfg.ConnKeepaliveInterval) * time.Second
|
||||
done := make(chan error)
|
||||
for {
|
||||
if kc > 0 {
|
||||
c.conn.SetReadDeadline(time.Now().Add(kc))
|
||||
}
|
||||
|
||||
// I still don't know why use goroutine can improve performance
|
||||
// if someone knows and benchamrks with another different result without goroutine, please tell me
|
||||
go func() {
|
||||
|
@ -91,7 +97,7 @@ func (c *respClient) run() {
|
|||
c.handleRequest(reqData)
|
||||
}
|
||||
|
||||
done <- nil
|
||||
done <- err
|
||||
}()
|
||||
|
||||
// reqData, err := c.readRequest()
|
||||
|
|
Loading…
Reference in New Issue