single worker & no locks

This commit is contained in:
NatureFreshMilk 2019-01-23 15:38:54 +01:00
parent 7622760c05
commit 65f51612df
4 changed files with 3 additions and 19 deletions

View File

@ -5,7 +5,6 @@ import (
"mapserver/coords"
"strconv"
"time"
"runtime"
"github.com/sirupsen/logrus"
)
@ -31,7 +30,6 @@ func Job(ctx *app.App) {
}
fields := logrus.Fields{
"jobs": runtime.NumCPU(),
"totalLegacyCount": totalLegacyCount,
}
logrus.WithFields(fields).Info("Starting initial rendering")
@ -42,9 +40,7 @@ func Job(ctx *app.App) {
jobs := make(chan *coords.TileCoords, 10)
for i:=0; i<runtime.NumCPU(); i++ {
go worker(ctx, jobs)
}
go worker(ctx, jobs)
for true {
start := time.Now()

View File

@ -13,8 +13,6 @@ delete from objects where posx = ? and posy = ? and posz = ?
`
func (db *Sqlite3Accessor) RemoveMapData(pos coords.MapBlockCoords) error {
mutex.Lock()
defer mutex.Unlock()
_, err := db.db.Exec(removeMapDataQuery, pos.X, pos.Y, pos.Z)
return err
}
@ -32,9 +30,6 @@ values(?, ?, ?)
`
func (db *Sqlite3Accessor) AddMapData(data MapObject) error {
mutex.Lock()
defer mutex.Unlock()
tx, err := db.db.Begin()
if err != nil {

View File

@ -9,8 +9,8 @@ import (
const migrateScript = `
PRAGMA foreign_keys = ON;
PRAGMA journal_mode = MEMORY;
PRAGMA synchronous = OFF;
-- PRAGMA journal_mode = MEMORY;
-- PRAGMA synchronous = OFF;
create table if not exists objects(
id integer primary key autoincrement,

View File

@ -4,11 +4,8 @@ import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
"mapserver/coords"
"sync"
)
var mutex = &sync.RWMutex{}
const getTileQuery = `
select data,mtime from tiles t
where t.layerid = ?
@ -57,8 +54,6 @@ values(?, ?, ?, ?, ?, ?)
`
func (db *Sqlite3Accessor) SetTile(tile *Tile) error {
mutex.Lock()
defer mutex.Unlock()
_, err := db.db.Exec(setTileQuery, tile.Pos.X, tile.Pos.Y, tile.Pos.Zoom, tile.Pos.LayerId, tile.Data, tile.Mtime)
return err
}
@ -69,8 +64,6 @@ where x = ? and y = ? and zoom = ? and layerid = ?
`
func (db *Sqlite3Accessor) RemoveTile(pos *coords.TileCoords) error {
mutex.Lock()
defer mutex.Unlock()
_, err := db.db.Exec(removeTileQuery, pos.X, pos.Y, pos.Zoom, pos.LayerId)
return err
}