<commit_before>/*
 * Copyright 2018 Analytics Zoo Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.intel.analytics.zoo.serving


import com.intel.analytics.zoo.pipeline.inference.{InferenceModel, InferenceSummary}
import com.intel.analytics.zoo.serving.utils._
import com.intel.analytics.zoo.serving.engine.InferenceSupportive
import com.intel.analytics.zoo.serving.engine.ServingReceiver
import com.intel.analytics.zoo.serving.pipeline.{RedisIO, RedisUtils}
import org.apache.log4j.{Level, Logger}
import org.apache.spark.broadcast.Broadcast
import org.apache.spark.streaming.{Duration, StreamingContext}
import redis.clients.jedis.{Jedis, JedisPool}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
import org.apache.spark.util.LongAccumulator
import com.intel.analytics.zoo.serving.utils.SerParams

object SparkStreamingClusterServing {
  Logger.getLogger("org").setLevel(Level.ERROR)
  Logger.getLogger("com.intel.analytics.zoo").setLevel(Level.INFO)


  case class Record(uri: String, value: String)

  def main(args: Array[String]): Unit = {

    val helper = new ClusterServingHelper()
    helper.initArgs()
    helper.initContext()

    /**
     * Variables need to be serialized are listed below
     * Take them from helper in advance for later execution
     */

    val modelType = helper.modelType
    val blasFlag = helper.blasFlag

    /**
     * chwFlag is to set image input of CHW or HWC
     * if true, the format is CHW
     * else, the format is HWC
     *
     * Note that currently CHW is commonly used
     * and HWC is often used in Tensorflow models
     */

    val logger = helper.logger

    /**
     * For cut input stream, this variable is to avoid
     * unsafe cut of input stream, if cut current batch
     * there is an interval between get and cut, this would
     * affect the result of correctness, some new data might be cut
     */

//    var model: InferenceModel = null
//    var bcModel: Broadcast[InferenceModel] = null

//    model = helper.loadInferenceModel()
//    bcModel = helper.sc.broadcast(model)



    val spark = helper.getSparkSession()

    logger.info(s"connected to redis " +
      s"${spark.conf.get("spark.redis.host")}:${spark.conf.get("spark.redis.port")}")



    var totalCnt: Int = 0
    var timeStamp: Int = 0

    // redis stream control

    val inputThreshold = 0.6 * 0.8
    val cutRatio = 0.5

    val acc = new LongAccumulator()
    helper.sc.register(acc)



    val localSerParams = new SerParams(helper)
    localSerParams.model.setInferenceSummary(
      InferenceSummary("./TensorboardEventLogs", helper.dateTime + "-ClusterServing"))
    val bcSer = helper.sc.broadcast(localSerParams)
<commit_msg>hf (#2810)<commit_after>/*
 * Copyright 2018 Analytics Zoo Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.intel.analytics.zoo.serving


import com.intel.analytics.zoo.pipeline.inference.{InferenceModel, InferenceSummary}
import com.intel.analytics.zoo.serving.utils._
import com.intel.analytics.zoo.serving.engine.InferenceSupportive
import com.intel.analytics.zoo.serving.engine.ServingReceiver
import com.intel.analytics.zoo.serving.pipeline.{RedisIO, RedisUtils}
import org.apache.log4j.{Level, Logger}
import org.apache.spark.broadcast.Broadcast
import org.apache.spark.streaming.{Duration, StreamingContext}
import redis.clients.jedis.{Jedis, JedisPool}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
import org.apache.spark.util.LongAccumulator
import com.intel.analytics.zoo.serving.utils.SerParams

object SparkStreamingClusterServing {
  Logger.getLogger("org").setLevel(Level.ERROR)
  Logger.getLogger("com.intel.analytics.zoo").setLevel(Level.INFO)


  case class Record(uri: String, value: String)

  def main(args: Array[String]): Unit = {

    val helper = new ClusterServingHelper()
    helper.initArgs()
    helper.initContext()

    /**
     * Variables need to be serialized are listed below
     * Take them from helper in advance for later execution
     */

    val modelType = helper.modelType
    val blasFlag = helper.blasFlag

    /**
     * chwFlag is to set image input of CHW or HWC
     * if true, the format is CHW
     * else, the format is HWC
     *
     * Note that currently CHW is commonly used
     * and HWC is often used in Tensorflow models
     */

    val logger = helper.logger

    /**
     * For cut input stream, this variable is to avoid
     * unsafe cut of input stream, if cut current batch
     * there is an interval between get and cut, this would
     * affect the result of correctness, some new data might be cut
     */

//    var model: InferenceModel = null
//    var bcModel: Broadcast[InferenceModel] = null

//    model = helper.loadInferenceModel()
//    bcModel = helper.sc.broadcast(model)



    val spark = helper.getSparkSession()

    logger.info(s"connected to redis " +
      s"${spark.conf.get("spark.redis.host")}:${spark.conf.get("spark.redis.port")}")



    var totalCnt: Int = 0
    var timeStamp: Int = 0

    // redis stream control

    val inputThreshold = 0.6 * 0.8
    val cutRatio = 0.5

    val acc = new LongAccumulator()
    helper.sc.register(acc)



    val localSerParams = new SerParams(helper)
    localSerParams.model = new InferenceModel()
    localSerParams.model.setInferenceSummary(
      InferenceSummary("./TensorboardEventLogs", helper.dateTime + "-ClusterServing"))
    val bcSer = helper.sc.broadcast(localSerParams)

{'fraction_non_alphanumeric': 0.0958111195734958, 'fraction_numerical': 0.005788271134805788, 'mean_word_length': 3.4941820670773445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5047829', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1912, 'n_words': 588}