Skip to content
Permalink
Browse files

hardcode 4 parallel workers

unfortunately, parsing seems is slower now :/
  • Loading branch information...
tyrasd committed Sep 4, 2016
1 parent ee6b453 commit 764f54ab3af4ae7b503b9b718a28a920589a6dea
Showing with 37 additions and 15 deletions.
  1. +25 −5 index.js
  2. +12 −10 worker.js
@@ -5,11 +5,24 @@ L.TileLayer.OsmTileAccessLogLayer = L.TileLayer.Canvas.extend({
data: null
},
messages: {},
worker: new Worker('worker.js'),
initialize: function (arrayBuffer) {
worker1: new Worker('worker.js'),
worker2: new Worker('worker.js'),
worker3: new Worker('worker.js'),
worker4: new Worker('worker.js'),
initialize: function (arrayBuffer1) {
var self = this
this.worker.postMessage(arrayBuffer, [arrayBuffer])
this.worker.onmessage = function(e) {
var arrayBuffer2 = arrayBuffer1.slice()
var arrayBuffer3 = arrayBuffer1.slice()
var arrayBuffer4 = arrayBuffer1.slice()
this.worker1.postMessage({tiles:1, data:arrayBuffer1}, [arrayBuffer1])
this.worker2.postMessage({tiles:2, data:arrayBuffer2}, [arrayBuffer2])
this.worker3.postMessage({tiles:3, data:arrayBuffer3}, [arrayBuffer3])
this.worker4.postMessage({tiles:0, data:arrayBuffer4}, [arrayBuffer4])
this.worker1.onmessage = tileHandler
this.worker2.onmessage = tileHandler
this.worker3.onmessage = tileHandler
this.worker4.onmessage = tileHandler
function tileHandler(e) {
var array = new Uint8Array(e.data.pixels)
var canvas = self.messages[e.data.tileId]
var ctx = canvas.getContext('2d')
@@ -22,7 +35,14 @@ L.TileLayer.OsmTileAccessLogLayer = L.TileLayer.Canvas.extend({
drawTile: function(canvas, tilePoint, zoom) {
var tileId=tilePoint.x+":"+tilePoint.y+":"+zoom
this.messages[tileId]=canvas
this.worker.postMessage({
var worker = null
switch (tilePoint.x%4) {
case 1: worker = this.worker1; break
case 2: worker = this.worker2; break
case 3: worker = this.worker3; break
case 0: worker = this.worker4; break
}
worker.postMessage({
tileId: tileId,
zoom: zoom,
tilePoint: tilePoint,
@@ -3,10 +3,10 @@ importScripts('rbush.js')
var tree = null;

self.addEventListener('message', function(e) {
if (e.data instanceof ArrayBuffer) {
if (e.data.data instanceof ArrayBuffer) {
// initialize with file content
console.time("parse data")
var view = new Uint8Array(e.data)
var view = new Uint8Array(e.data.data)
var data = []
var currentInt = 0
var currentCoords = []
@@ -16,14 +16,16 @@ self.addEventListener('message', function(e) {
currentInt = currentInt*10 + (view[i] - 48 /*'0'*/)
break;
case 10: // '\n'
data.push({
minX: currentCoords[1],
maxX: currentCoords[1],
minY: currentCoords[2],
maxY: currentCoords[2],
zoom: currentCoords[0],
count: currentInt
})
if (~~(currentCoords[1]/256)%4 === e.data.tiles) {
data.push({
minX: currentCoords[1],
maxX: currentCoords[1],
minY: currentCoords[2],
maxY: currentCoords[2],
zoom: currentCoords[0],
count: currentInt
})
}
currentCoords = []
currentInt = 0
break;

0 comments on commit 764f54a

Please sign in to comment.
You can’t perform that action at this time.