mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 01:00:18 +01:00
Uses sync.Pool to recycle some memory. Makes it 1.3. TODO: Find out if it is worth the effort.
This commit is contained in:
parent
d51ecc6eef
commit
8a474ddd65
@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"bitbucket.org/s_l_teichmann/mtredisalize/common"
|
||||
)
|
||||
@ -54,10 +55,12 @@ func copyProducerToConsumer(producer BlockProducer, consumer BlockConsumer) erro
|
||||
done := make(chan struct{})
|
||||
defer close(done)
|
||||
|
||||
pool := sync.Pool{New: func() interface{} { return new(Block) }}
|
||||
|
||||
go func() {
|
||||
defer close(blocks)
|
||||
for {
|
||||
block := new(Block)
|
||||
block := pool.Get().(*Block)
|
||||
if err := producer.Next(block); err != nil {
|
||||
if err != ErrNoMoreBlocks {
|
||||
log.Printf("Reading failed: %s\n", err)
|
||||
@ -77,6 +80,8 @@ func copyProducerToConsumer(producer BlockProducer, consumer BlockConsumer) erro
|
||||
if err := consumer.Consume(block); err != nil {
|
||||
return err
|
||||
}
|
||||
block.Data = nil
|
||||
pool.Put(block)
|
||||
i++
|
||||
if i%1000 == 0 {
|
||||
log.Printf("%d blocks transferred.\n", i)
|
||||
|
Loading…
Reference in New Issue
Block a user