Back when I made one of my first Meteor apps, I needed a simple mechanism to send reminder emails. I began to look into various job queues, but I found them all to be a bit overwhelming. Instead, I hacked up my own solution, and later built it up into this package.
The Steve Jobs package works well with Meteor’s opinionated approach, and it’s designed to be very familiar for Meteor developers. Notice how similar it is to writing your own Methods:
Would it be possible to use this package in the app and spin up another Meteor instance (capped with only the must-have plugins) to run the jobs?
As far as I understood we have to register the job and it will run on the same server(s).
As the plugin just pulls from the DB every X seconds for jobs, I think would be very useful to be able to separate the execution of the job from the “insertion” of the job".
What do you think?
PS: Even if the concept is to make it simple and to “just work” it would be a welcome evolution.
Thanks man! A microservice mode is something in consideration, I am thinking of what would be the best way to implement it.
However - with the one job at a time approach, the performance impact of the package is so minimal, so it may not be worth it until the feature set is expanded.
Maybe there should first be a way to run multiple jobs at once, though I like the fact that jobs run predictably and in order.
nice
+1 on the feature req for having the worker run as a separate uservice.
atm I run my own (buggy) code which runs the jobs, would love to drop it and use a standardized package
btw, would be nice to run more then one job per sec/ for example if the job is image processing and the app runs on a multi core machine. Would be nice to churn thru the images as fast as the cpu is capable of.
Won’t be able to do that on a single threaded process like all node.js apps are. You’ll need to spawn several instances of the server and have a way to cluster them.
If image processing is being run by a native library such as https://www.imagemagick.org then it’s treated like an IO operation, no? You set it up similarly to any other IO op (e.g. sending an http request) and when it’s complete you get a callback.
Also check here: https://guide.meteor.com/structure.html it writes
In Meteor, your server code runs in a single thread per request, not in the asynchronous callback style typical of Node
I understand from this that in such cases meteor will benefit from a multi-threaded (core) cpu. But again, it’s assuming that the native code is fired up as an IO op to exec the heavy lifting
No, meteor runs on node and node is inherently single threaded (event loop). The only way to run on multiple cores is to cluster to multiple instances.
The quote you mentioned is just the way you write server code, you write synchronous code but it runs asynchronously (read up on fibers).
My 2 cents on job queues: I’ve scaled to a much larger infrastructure than just meteor servers, so we have microservices for specific processes. The central communication process for all this is a messaging layer, think rabbitMQ, kafka, google pub/sub, redis. Utilizing this for job queues is more secure, stable and flexible and allows you to have multiple microservices run jobs concurrently or run microservices written in multithreaded languages (golang for example) and process the jobs in parallel that way. Also consider serverless architectures to process certain things (aws lambda, gestalt), can be extremely cost-effective in some cases.
Of course this has nothing to do with a meteor/npm package and for smaller/early projects that’s overkill, just wanted to address how to scale the processing of jobs, either cluster meteor servers or build on microservices/serverless architecture.
Thanks for your feedback man. As people mentioned above, this package, or perhaps even Node.js, may not be the right solution for that. However, we do have some discussions about running more than one job at a time, among other things, and it would be great to get your take on it.
I have an app which schedules messages to be sent at predetermined dates in the future (anywhere from a few minutes from ‘now’ to 6 months from ‘now’). The way I currently do it seems very inefficient and I’m looking for solutions to optimise.
Current process:
Write a message to be sent, into the database, with the status: ‘queued’
Have a cron job that polls the database every 30 seconds and send off messages with the status ‘queued’ that have hit their due date since the last time the job was run (i.e. since 30 seconds ago)
(Once you’re done spewing at how resource intensive and unscaleable that process is…)
I wonder whether this may be a great alternative. I.e. The new process would be:
Write a message to be sent into the db, and while doing so, call Jobs.run with the config object
Done!
Questions I need to dig into the code/find out:
Does the job queue survive server restarts? Does it use the mongo db to persist when jobs need to be called?
Update - Reading the Github docs it seems so… Great!
Performance - is it more optimal for memory/resource usage than a very frequent cron job?
Thanks for the positive response It should work fine on one container or one hundred. The package will claim one container to do its job, and if that container goes down, it will claim another one. The performance impact is minimal - running a job should cost you about the same as running a method.