Unfortunately I'm afraid that I don't see how a scheduler can avoid the concurrency problems. Note that the advantages (e.g. in availability) of having a cluster should be maintained here, and so you cannot run a scheduler in a separate process on a single server. If every server would be running the scheduler, the same concurrency problems would arise. What were you proposing?
About the initialization, I guess that would work. It is not the way I would prefer to do it, as I would like the application to be self-controlled and usable without running special tools, but I reckon it is an acceptable approach. Tom Op vrijdag 5 oktober 2012 19:59:33 UTC+7 schreef greelgorke het volgende: > > i wouldn't do it that way. when deploying your app just do a pre-start > script, that ensures the existence of your desired data. > If you have periodical tasks, it's best to use a lib for it, that triggers > jobs appart of your main application. i.E > http://stackoverflow.com/questions/3785736/is-there-a-job-scheduler-library-for-node-js, > so you just avoid the concurrency problems. > > Am Freitag, 5. Oktober 2012 14:04:58 UTC+2 schrieb Tom: >> >> I've setup a cluster of physical servers. Each server runs exactly the >> same code. Moreover, each server runs multiple node processes using >> the build in cluster functionality. >> >> I use MongoDB (native) to share information between processes and >> servers. However, I am having some difficulty with running a special task >> that needs to be executed only once during initialization: >> > if a special `admin` account does not yet exist in the database, it >> should be created >> >> Originally I figured that I could read from the MongoDB master server on >> each node and check if the admin account already exists. If it does not >> then another node has not yet created it, so this node should do so. >> However this is problematic because creating an admin password hash is >> asynchronous and takes time. Therefore there is a delay between when a node >> decides to create the account and when the account is being found by other >> nodes when querying the database. >> >> The code snippet that reads from the Mongo master only and creates the >> account is available here: https://gist.github.com/3839429 >> >> In the future I would also like a special task to be executed every 5 >> minutes. This task must then only be executed by a running server, and not >> by all servers. >> >> In short: when running a cluster of servers, how do you coordinate >> between these servers which of them is going to execute a sole task such as >> the one described above? >> >> Tom >> > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en