Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/maptalks/src/core/worker/WorkerPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ export default class WorkerPool {
_messages: MessageBatch[][]
//@internal
_messageBuffers: ArrayBuffer[]
//@internal
_idleLoopCount: number;
workers: Worker[]
constructor() {
this._idleLoopCount = 0;
this.active = {};
this.workerCount = typeof window !== 'undefined' ? (GlobalConfig.workerCount || hardwareWorkerCount) : 0;
this._messages = [];
Expand Down Expand Up @@ -125,9 +128,16 @@ export default class WorkerPool {
}

broadcastIdleMessage(messageRatio: number) {
//目前idle空转情况严重,没有必要频率这么高,简单的限制下
if (this._idleLoopCount < 3) {
this._idleLoopCount++;
return this;
}
this._idleLoopCount = 0;
const workers = this.getWorkers();
const message = { messageType: 'idle', messageRatio };
workers.forEach(worker => {
worker.postMessage({ messageType: 'idle', messageRatio });
worker.postMessage(message);
});
return this;
}
Expand Down