mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-25 15:40:22 +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
|
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) {
|
func (client *RedisClient) QueryCuboid(cuboid Cuboid, fn func(*Block)) (count int, err error) {
|
||||||
p1 := CoordToPlain(cuboid.P1)
|
p1 := CoordToPlain(cuboid.P1)
|
||||||
p2 := CoordToPlain(cuboid.P2)
|
p2 := CoordToPlain(cuboid.P2)
|
||||||
if err = client.writeHSpatial(p1, p2); err != nil {
|
if err = client.writeHSpatial(p1, p2); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data := dataPool.Get().([]byte)
|
||||||
|
defer dataPool.Put(data[:0])
|
||||||
|
|
||||||
var (
|
var (
|
||||||
data = make([]byte, 8*1024)
|
|
||||||
block = Block{}
|
block = Block{}
|
||||||
size int
|
size int
|
||||||
key int64
|
key int64
|
||||||
@ -164,14 +173,14 @@ func (client *RedisClient) QueryCuboid(cuboid Cuboid, fn func(*Block)) (count in
|
|||||||
if size <= 0 {
|
if size <= 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if key, err = DecodeStringFromBytes(data[0:size]); err != nil {
|
if key, err = DecodeStringFromBytes(data[:size]); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
block.Coord = PlainToCoord(key)
|
block.Coord = PlainToCoord(key)
|
||||||
if size, err = client.readBulkString(&data); err != nil || size < 0 {
|
if size, err = client.readBulkString(&data); err != nil || size < 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
block.Data = data[0:size]
|
block.Data = data[:size]
|
||||||
fn(&block)
|
fn(&block)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user