The block data from the redis server in of the HSPATIAL requests is now recycled with a sync.Pool. Removes some pressure from the gc.

This commit is contained in:
Sascha L. Teichmann 2017-02-28 00:33:59 +01:00
parent d6411f3f6d
commit 5def145564
1 changed files with 12 additions and 3 deletions

View File

@ -144,14 +144,23 @@ func (client *RedisClient) readBulkString(data *[]byte) (size int, err error) {
return
}
var dataPool = sync.Pool{
New: func() interface{} {
return make([]byte, 8*1024)
},
}
func (client *RedisClient) QueryCuboid(cuboid Cuboid, fn func(*Block)) (count int, err error) {
p1 := CoordToPlain(cuboid.P1)
p2 := CoordToPlain(cuboid.P2)
if err = client.writeHSpatial(p1, p2); err != nil {
return
}
data := dataPool.Get().([]byte)
defer dataPool.Put(data[:0])
var (
data = make([]byte, 8*1024)
block = Block{}
size int
key int64
@ -164,14 +173,14 @@ func (client *RedisClient) QueryCuboid(cuboid Cuboid, fn func(*Block)) (count in
if size <= 0 {
break
}
if key, err = DecodeStringFromBytes(data[0:size]); err != nil {
if key, err = DecodeStringFromBytes(data[:size]); err != nil {
return
}
block.Coord = PlainToCoord(key)
if size, err = client.readBulkString(&data); err != nil || size < 0 {
return
}
block.Data = data[0:size]
block.Data = data[:size]
fn(&block)
}