Skip to content

Commit

Permalink
Cluster Serving baseline and refactor (intel-analytics#2961)
Browse files Browse the repository at this point in the history
  • Loading branch information
Litchilitchy committed Oct 15, 2020
1 parent a773ce3 commit e2ba288
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.util.concurrent.LinkedBlockingQueue
import java.util.{List => JList}

import com.intel.analytics.bigdl.nn.abstractnn.Activity
import com.intel.analytics.zoo.serving.engine.ModelHolder

import scala.collection.JavaConverters._

Expand Down Expand Up @@ -509,15 +510,15 @@ class InferenceModel(private var autoScalingEnabled: Boolean = true,
}

private def predict(inputActivity: Activity): Activity = {
val model: AbstractModel = retrieveModel()
val model = retrieveModel()
try {
val begin = System.nanoTime()
val result = model.predict(inputActivity)
val end = System.nanoTime()

val latency = end - begin
val name = s"model predict for batch"
InferenceSupportive.logger.info(s"$name time elapsed [${latency/1e9} s, ${latency/1e6} ms].")
val name = s"Thread ${Thread.currentThread().getId} Inference"
InferenceSupportive.logger.info(s"$name time [${latency/1e9} s, ${latency/1e6} ms].")

result
} finally {
Expand Down Expand Up @@ -549,13 +550,7 @@ class InferenceModel(private var autoScalingEnabled: Boolean = true,
}
}
}
def blockModel(): Unit = {
while (modelQueue.peek() == null) {
val model = modelQueue.take()
modelQueue.offer(model)
}

}
private def retrieveModel(): AbstractModel = {
var model: AbstractModel = null
autoScalingEnabled match {
Expand All @@ -565,7 +560,8 @@ class InferenceModel(private var autoScalingEnabled: Boolean = true,
model = modelQueue.take
} catch {
case e: InterruptedException =>
throw new InferenceRuntimeException("no model available", e);
throw new InferenceRuntimeException("no model available \n"
+ e.getStackTrace.mkString("\n"))
}
case true =>
// if auto-scaling is enabled, will poll a model, no waiting but scale 1 model if necessary.
Expand Down

0 comments on commit e2ba288

Please sign in to comment.