2

I have created a simple Play plugin that creates user notifications. This is done by using a tailable, capable collection.

lazy val unprocessed: Future[Enumerator[Event]] = {

  for {
    coll <- collection
  } yield coll.find(Json.obj("processed" -> false))
      .options(QueryOpts().tailable.awaitData)
      .cursor[Event]
      .enumerate()
}

The plugin starts at application start and uses an Iteratee with this Enumerator

val itr = Iteratee.foreach[Event](e => {
    // Intentionally left empty for now 
})
EventDao.unprozessed map(_.apply(itr))

Whith this code all requests - also those that don't touch the collections/Enumerators used here will respond at least 5x slower than before. I already tried to move those two segments above into a new execution context but this didn't help. As soon as I comment out EventDao.unprozessed the speed is back to normal. So it seems as if the runtime gets occupied watching the tailable collection.

What is happening here behind the scenes?

DanielKhan
  • 1,190
  • 1
  • 9
  • 18

0 Answers0