Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

worker usage should be customizable #3982

Closed
jfirebaugh opened this issue Feb 17, 2016 · 3 comments
Closed

worker usage should be customizable #3982

jfirebaugh opened this issue Feb 17, 2016 · 3 comments
Labels
Node.js node-mapbox-gl-native refactor

Comments

@jfirebaugh
Copy link
Contributor

For node, we don't want to spawn four threads for each Map instance. Instead, the node thread pool should be used.

Worker needs to be more like FileSource -- an abstract interface that can be replaced with different implementations depending on the platform.

@jfirebaugh jfirebaugh added refactor Node.js node-mapbox-gl-native labels Feb 17, 2016
@tmpsantos
Copy link
Contributor

Wouldn't make mbgl::Worker thread-safe (it is almost already) and share it across all the map objects a more maintainable option?

@jfirebaugh
Copy link
Contributor Author

It wouldn't be ideal for node. Node already has a built-in concept of a thread worker pool, which native extensions are expected to use for CPU-intensive tasks. The right thing for an extension to do is use that pool, not launch its own threads.

@jfirebaugh
Copy link
Contributor Author

We now have an abstract interface that can facilitate this: Scheduler. We could, for example, write a subclass that implements Scheduler::schedule via Nan::AsyncQueueWorker. The worker Execute implementation would do:

if (auto locked = mailbox.lock()) {
    locked->receive();
}

(Actually this logic is already repeated here and here and we should extract it as static void Mailbox::maybeReceive(std::weak_ptr<Mailbox>).)

The other thing we need to do is externalize the dependency, passing a Scheduler& into the Map constructor as we do View& and FileSource&, rather than creating it internally. This will need to be a coordinated change across all SDKs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Node.js node-mapbox-gl-native refactor
Projects
None yet
Development

No branches or pull requests

2 participants