enable concurrent writing explicitly
parent
a406864fd7
commit
af6510b008
|
@ -167,6 +167,7 @@ func Import() {
|
||||||
relWriter := writer.NewRelationWriter(osmCache, diffCache, relations,
|
relWriter := writer.NewRelationWriter(osmCache, diffCache, relations,
|
||||||
db, progress, config.BaseOptions.Srid)
|
db, progress, config.BaseOptions.Srid)
|
||||||
relWriter.SetLimiter(geometryLimiter)
|
relWriter.SetLimiter(geometryLimiter)
|
||||||
|
relWriter.EnableConcurrent()
|
||||||
relWriter.Start()
|
relWriter.Start()
|
||||||
relWriter.Wait() // blocks till the Relations.Iter() finishes
|
relWriter.Wait() // blocks till the Relations.Iter() finishes
|
||||||
osmCache.Relations.Close()
|
osmCache.Relations.Close()
|
||||||
|
@ -175,6 +176,7 @@ func Import() {
|
||||||
wayWriter := writer.NewWayWriter(osmCache, diffCache, ways, db,
|
wayWriter := writer.NewWayWriter(osmCache, diffCache, ways, db,
|
||||||
progress, config.BaseOptions.Srid)
|
progress, config.BaseOptions.Srid)
|
||||||
wayWriter.SetLimiter(geometryLimiter)
|
wayWriter.SetLimiter(geometryLimiter)
|
||||||
|
wayWriter.EnableConcurrent()
|
||||||
wayWriter.Start()
|
wayWriter.Start()
|
||||||
wayWriter.Wait() // blocks till the Ways.Iter() finishes
|
wayWriter.Wait() // blocks till the Ways.Iter() finishes
|
||||||
osmCache.Ways.Close()
|
osmCache.Ways.Close()
|
||||||
|
@ -183,6 +185,7 @@ func Import() {
|
||||||
nodeWriter := writer.NewNodeWriter(osmCache, nodes, db,
|
nodeWriter := writer.NewNodeWriter(osmCache, nodes, db,
|
||||||
progress, config.BaseOptions.Srid)
|
progress, config.BaseOptions.Srid)
|
||||||
nodeWriter.SetLimiter(geometryLimiter)
|
nodeWriter.SetLimiter(geometryLimiter)
|
||||||
|
nodeWriter.EnableConcurrent()
|
||||||
nodeWriter.Start()
|
nodeWriter.Start()
|
||||||
nodeWriter.Wait() // blocks till the Nodes.Iter() finishes
|
nodeWriter.Wait() // blocks till the Nodes.Iter() finishes
|
||||||
osmCache.Close()
|
osmCache.Close()
|
||||||
|
|
|
@ -28,14 +28,23 @@ type OsmElemWriter struct {
|
||||||
writer looper
|
writer looper
|
||||||
srid int
|
srid int
|
||||||
expireTiles *expire.Tiles
|
expireTiles *expire.Tiles
|
||||||
|
concurrent bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (writer *OsmElemWriter) SetLimiter(limiter *limit.Limiter) {
|
func (writer *OsmElemWriter) SetLimiter(limiter *limit.Limiter) {
|
||||||
writer.limiter = limiter
|
writer.limiter = limiter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (writer *OsmElemWriter) EnableConcurrent() {
|
||||||
|
writer.concurrent = true
|
||||||
|
}
|
||||||
|
|
||||||
func (writer *OsmElemWriter) Start() {
|
func (writer *OsmElemWriter) Start() {
|
||||||
for i := 0; i < runtime.NumCPU(); i++ {
|
concurrency := 1
|
||||||
|
if writer.concurrent {
|
||||||
|
concurrency = runtime.NumCPU()
|
||||||
|
}
|
||||||
|
for i := 0; i < concurrency; i++ {
|
||||||
writer.wg.Add(1)
|
writer.wg.Add(1)
|
||||||
go writer.writer.loop()
|
go writer.writer.loop()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue