mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-11 01:10:17 +01:00
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:
parent
d6411f3f6d
commit
5def145564
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user