diff --git a/import_/import.go b/import_/import.go index bb51cd4..7c8c297 100644 --- a/import_/import.go +++ b/import_/import.go @@ -167,6 +167,7 @@ func Import() { relWriter := writer.NewRelationWriter(osmCache, diffCache, relations, db, progress, config.BaseOptions.Srid) relWriter.SetLimiter(geometryLimiter) + relWriter.EnableConcurrent() relWriter.Start() relWriter.Wait() // blocks till the Relations.Iter() finishes osmCache.Relations.Close() @@ -175,6 +176,7 @@ func Import() { wayWriter := writer.NewWayWriter(osmCache, diffCache, ways, db, progress, config.BaseOptions.Srid) wayWriter.SetLimiter(geometryLimiter) + wayWriter.EnableConcurrent() wayWriter.Start() wayWriter.Wait() // blocks till the Ways.Iter() finishes osmCache.Ways.Close() @@ -183,6 +185,7 @@ func Import() { nodeWriter := writer.NewNodeWriter(osmCache, nodes, db, progress, config.BaseOptions.Srid) nodeWriter.SetLimiter(geometryLimiter) + nodeWriter.EnableConcurrent() nodeWriter.Start() nodeWriter.Wait() // blocks till the Nodes.Iter() finishes osmCache.Close() diff --git a/writer/writer.go b/writer/writer.go index 1f3d38b..20ecc58 100644 --- a/writer/writer.go +++ b/writer/writer.go @@ -28,14 +28,23 @@ type OsmElemWriter struct { writer looper srid int expireTiles *expire.Tiles + concurrent bool } func (writer *OsmElemWriter) SetLimiter(limiter *limit.Limiter) { writer.limiter = limiter } +func (writer *OsmElemWriter) EnableConcurrent() { + writer.concurrent = true +} + 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) go writer.writer.loop() }