Last active
December 17, 2015 11:49
-
-
Save felipehummel/5605559 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object MyActor { | |
val inProgress = metrics.counter("fetching-in-progress") // yammer/coda hales metrics | |
} | |
// I have around 25.000 actors of this type running | |
// runs on my-dispatcher | |
class MyActor extends Actor { | |
val id = ... | |
implicit val ec = context.system.dispatchers.lookup("dispatcher-for-IO-stuff") | |
override def preStart = { | |
context.system.scheduler.scheduleOnce(timeToInitialJob +, self, DoJob) | |
} | |
def receive = { | |
case ... => ... // sporadic and simple thing every few minutes | |
case HealthCheck => { // every few minutes | |
if (/** it has been way too long since we did something useful **/) { | |
throw new Exception("It has been too long since it did some job. It'll be restarted") // actually committing suicide | |
} | |
} | |
case DoJob => { | |
inProgress += 1 | |
lastJobAt = new Date | |
logger.debug("Received stuff") | |
Future { // using dispatcher-for-IO-stuff | |
// IO stuff, first fetching URLs and then searching DB | |
logger.debug("Piping it back") | |
SuccessfulProcessing(...) // will be piped to self | |
} recover { | |
case e: Exception => FailedFetch(e) | |
} pipeTo self | |
} | |
case SuccessfulProcessing(...) => { | |
... | |
inProgress -= 1 | |
logger.debug("Done with Job to fetch") | |
context.system.scheduler.scheduleOnce(delay(), self, DoJob) | |
... | |
} | |
case FailedFetch(throwable) => { | |
... | |
inProgress -= 1 | |
logger.debug("Done with Job Failed to fetch") | |
context.system.scheduler.scheduleOnce(delay(), self, DoJob) | |
... | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my-dispatcher { | |
# Dispatcher is the name of the event-based dispatcher | |
type = Dispatcher | |
executor = "thread-pool-executor" | |
thread-pool-executor { | |
core-pool-size-min = 1 | |
core-pool-size-factor = 2 | |
core-pool-size-max = 8 | |
} | |
throughput = 5 | |
} | |
dispatcher-for-IO-stuff { | |
type = Dispatcher | |
executor = "thread-pool-executor" | |
thread-pool-executor { | |
core-pool-size-min = 10 | |
core-pool-size-factor = 2.0 | |
core-pool-size-max = 16 | |
} | |
throughput = 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment