Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-3578

Avoiding MongoWaitQueueFullExceptions by overriding ObservableImplicits

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.0.0
    • Affects Version/s: None
    • Component/s: Scala
    • Labels:
      None
    • Minor Change

      We would like to apply some throttling on mongo queries to avoid hitting MongoWaitQueueFullExceptions at runtime. We would also like to apply this non-invasively to our current mongo api usage.

      We have managed to do this by providing alternative implicit conversions, in the same way as those in `org.mongodb.scala.ObservableImplicits`, where our version of `toFuture` (and `toFutureOption`) would evaluate the `observable: Observable` on a fixed-size thread-pool.

      The observable, which the extra methods are added to, needs to be captured as a by-name parameter, in-order that we can evaluate it on our thread-pool, e.g. `implicit class ScalaObservable[T](observable: => Observable[T])`.

      But since an implicit for a by-name parameter is picked up secondary to a by-value parameter, we are unable to override the predefined `toFuture` function, and have to create a new function (e.g. `toFutureThrottled`).

      If the provided implicit classes in `ObservableImplicits`:

        `implicit class ScalaObservable[T](observable: Observable[T])`

      were changed to:
      ```

      implicit class ScalaObservable[T](observable: => Observable[T]) {
        val obs = observable
       …
      

      ```

      (and ScalaSingleObservable similarly), then we could override them, such that `toFuture` behaves as we intend.

      Is this worth a pull-request, to change the observable parameter from a by-value to a by-name parameter?

      Or is there an alternative recommendation for achieving this goal?

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            colin.fairless@digital.hmrc.gov.uk Colin Fairless
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: