add conn keep alive check and bug fix

This commit is contained in:
siddontang 2014-10-30 11:11:45 +08:00
parent 89c58e45ca
commit b9b60f19ad
4 changed files with 20 additions and 3 deletions

View File

@ -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"`
}

View File

@ -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

View File

@ -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

View File

@ -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()