<commit_before>package com.despegar.metrik.stress

import java.util.concurrent.Executors

import com.despegar.metrik.model.{ MetricMeasurement, Measurement, MetricBatch }

import scala.concurrent.Await
import scala.util.Random

object StressTest extends App {

  doIt()

  def showHowToDoIt() = {
    println("StressTest concurrent times sleep nMetrics nMeasurements")
    System.exit(0)
  }

  def doIt(): Unit = {
    if (args.length < 1) {
      showHowToDoIt()
    }

    val c = args(0).toInt
    val n = args(1).toInt
    val sleep = args(2).toLong
    val nMetrics = args(3).toInt
    val nnMeasurements = args(4).toInt

    val random = new Random()

    val executor = Executors.newFixedThreadPool(c)

    var j = 0
    do {
      j += 1
      val tasks = for (i ← 1 to c) yield {
        executor.submit(new Runnable {
          override def run(): Unit = {
            postToMetrikApi(i, j)
          }
        })
      }

      Thread.sleep(sleep)
      tasks foreach (task ⇒ task.get())
    } while (j < n)

    def postToMetrikApi(call: Int, run: Int): Unit = {
      val metricMeasurements = (for (i ← 1 to nMetrics) yield MetricMeasurement(s"metric$i", "timer", getMeasurements())) toList

      println(s"calling Metrik #$call, run #$run ${MetricBatch(metricMeasurements)}")
    }

    def getMeasurements(): List[Measurement] = {
      List(Measurement(System.currentTimeMillis(), getMeasurementValues()))
    }

    def getMeasurementValues(): Seq[Long] = {
      for (i ← 1 to nnMeasurements) yield (random.nextInt(10000)).toLong
    }
  }
}
<commit_msg>stress test<commit_after>package com.despegar.metrik.stress

import java.util.concurrent.Executors
import akka.actor.{ Props, ActorSystem }
import spray.http._
import spray.client.pipelining._

import com.despegar.metrik.model.{ MetricBatchProtocol, Measurement, MetricBatch, MetricMeasurement }

import scala.concurrent.Future
import scala.util.{ Success, Failure, Random }
import spray.http._
import spray.client.pipelining._

import MetricBatchProtocol._

object StressTest extends App {
  implicit val system = ActorSystem("StressActorSystem")
  import system.dispatcher // execution context for futures

  doIt()

  def showHowToDoIt() = {
    println("StressTest concurrent times sleep nMetrics nMeasurements")
    System.exit(0)
  }

  def doIt(): Unit = {
    if (args.length < 1) {
      showHowToDoIt()
    }

    val c = args(0).toInt
    val n = args(1).toInt
    val sleep = args(2).toLong
    val nMetrics = args(3).toInt
    val nnMeasurements = args(4).toInt

    val random = new Random()

    val executor = Executors.newFixedThreadPool(c)

    var j = 0
    do {
      j += 1
      val tasks = for (i ← 1 to c) yield {
        executor.submit(new Runnable {
          override def run(): Unit = {
            postToMetrikApi(i, j)
          }
        })
      }

      Thread.sleep(sleep)
      tasks foreach (task ⇒ task.get())
    } while (j < n)

    def postToMetrikApi(call: Int, run: Int): Unit = {
      val metricMeasurements = (for (i ← 1 to nMetrics) yield MetricMeasurement(s"cachorra$i", "timer", getMeasurements())) toList

      val metricBatch: MetricBatch = MetricBatch(metricMeasurements)
      println(s"calling Metrik #$call, run #$run")

      val request = Post("http://ht-core-01:8080/metrik/metrics", metricBatch)
      val pipeline: HttpRequest ⇒ Future[HttpResponse] = sendReceive

      val response = pipeline(request)
      response onComplete {
        case Failure(ex)   ⇒ ex.printStackTrace()
        case Success(resp) ⇒ println("success: " + resp.status)
      }
    }

    def getMeasurements(): List[Measurement] = {
      List(Measurement(System.currentTimeMillis(), getMeasurementValues()))
    }

    def getMeasurementValues(): Seq[Long] = {
      for (i ← 1 to nnMeasurements) yield (random.nextInt(10000)).toLong
    }

    println("Ending...")
    executor.shutdown()
    system.shutdown()
  }
}

{'fraction_non_alphanumeric': 0.11727295853472398, 'fraction_numerical': 0.010175527855507505, 'mean_word_length': 2.9280719280719283, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5009713', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1257, 'n_words': 317}