add conn buffer config

This commit is contained in:
siddontang 2014-10-25 14:48:52 +08:00
parent 57d60b0ce0
commit 53072735f6
3 changed files with 17 additions and 4 deletions

View File

@ -110,6 +110,9 @@ type Config struct {
Replication ReplicationConfig `toml:"replication"`
Snapshot SnapshotConfig `toml:"snapshot"`
ConnReadBufferSize int `toml:"conn_read_buffer_size"`
ConnWriteBufferSize int `toml:"conn_write_buffer_size"`
}
func NewConfigWithFile(fileName string) (*Config, error) {
@ -191,6 +194,8 @@ func (cfg *Config) adjust() {
cfg.RocksDB.adjust()
cfg.Replication.ExpiredLogDays = getDefault(7, cfg.Replication.ExpiredLogDays)
cfg.ConnReadBufferSize = getDefault(4*KB, cfg.ConnReadBufferSize)
cfg.ConnWriteBufferSize = getDefault(4*KB, cfg.ConnWriteBufferSize)
}
func (cfg *LevelDBConfig) adjust() {

View File

@ -43,6 +43,10 @@ db_sync_commit = 0
# enable replication or not
use_replication = true
# set connection buffer, you can increase them appropriately
conn_read_buffer_size = 10240
conn_write_buffer_size = 10240
[leveldb]
# for leveldb and goleveldb
compression = false

View File

@ -33,9 +33,13 @@ func newClientRESP(conn net.Conn, app *App) {
c.client = newClient(app)
c.conn = conn
c.rb = bufio.NewReaderSize(conn, 4096)
if tcpConn, ok := conn.(*net.TCPConn); ok {
tcpConn.SetReadBuffer(app.cfg.ConnReadBufferSize)
tcpConn.SetWriteBuffer(app.cfg.ConnWriteBufferSize)
}
c.rb = bufio.NewReaderSize(conn, app.cfg.ConnReadBufferSize)
c.resp = newWriterRESP(conn)
c.resp = newWriterRESP(conn, app.cfg.ConnWriteBufferSize)
c.remoteAddr = conn.RemoteAddr().String()
go c.run()
@ -158,9 +162,9 @@ func (c *respClient) handleRequest(reqData [][]byte) {
// response writer
func newWriterRESP(conn net.Conn) *respWriter {
func newWriterRESP(conn net.Conn, size int) *respWriter {
w := new(respWriter)
w.buff = bufio.NewWriterSize(conn, 256)
w.buff = bufio.NewWriterSize(conn, size)
return w
}