Play 2 Heroku startup with multiple dynos

前端 未结 2 1846
余生分开走
余生分开走 2021-01-01 05:36

I have a Play 2.x app up and running on Heroku with a single web dyno.

On startup, an Akka actor is triggered which itself schedules future jobs (e.g. sending push n

2条回答
  •  情书的邮戳
    2021-01-01 06:11

    If you run two web dynos, your global will be executed twice. Global is global to the process. When you scale your web process, you are running two processes. You have a couple options:

    • Use a different process (aka a singleton process) to run your global. The nice thing about Play is that you can have multiple GlobalSettings implementations. When you start your process, you specify the global you want to use with -Dapplication.global=YourSecondGlobal. In your procfile, then, you would have singleton: target/start -Dhttp.port=${PORT} ${JAVA_OPTS} -Dapplication.global=YourSecondGlobal. Start your web processes and singleton process and make sure singleton is scaled to 1.
    • Use a distributed semaphor to obtain a lock. Each process will then race to obtain a lock -- the one that wins will proceed and the others will fail. If you're using Postgres (as many people do on Heroku), an advisory lock is a good choice.

提交回复
热议问题