Commit c194e06f authored by Paul Asmuth's avatar Paul Asmuth
Browse files

improve response time for VALUESIN queries with large ranges by 480% :)...

improve response time for VALUESIN queries with large ranges by 480% :) (2200ms to 45ms for 25k samples)
parent b7b9dbba
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -66,8 +66,8 @@ class SwapFile(metric_key: MetricKey) {
  def load_chunk(position: Int, dst: ListBuffer[(Long, Double)]) : Int = {
    var read_pos = 0

    // we read the data back in 540 byte blocks (30 samples per block)
    var chunk_size = BLOCK_SIZE * 30
    // we read the data back in 65535 byte blocks (3640 samples per block)
    var chunk_size = BLOCK_SIZE * 3640
    val chunk = ByteBuffer.allocate(chunk_size)

    if (position < chunk_size)
+14 −7
Original line number Diff line number Diff line
@@ -12,22 +12,29 @@ class ValuesInInstruction(key: MetricKey, time0: Long, time1: Long) extends Abst
  def execute : String = {
    val metric = MetricFactory.get_metric(key)
    val values = metric.values_in(time1 * 1000, time0 * 1000)
    val resp = new StringBuffer

    // we estimate that every tuple will need around 25 byte in its
    // ascii representation
    val resp = new StringBuffer(values.size * 25)

    if (values.size == 0)
      return "null"

    for (ind <- (0 until values.size)) {
      resp.append(values(ind)._1)
    values.foreach { cur =>
      resp.append(cur._1)
      resp.append(":")

      resp.append(FnordMetric.number_format.format((
        values(ind)._2)))
      resp.append(FnordMetric.number_format.format(cur._2))

      if (ind < values.size - 1)
      // if this is the last item, we write an extra whitespace
      // character as checking for the last item would be expensive
      resp.append(" ")
    }

    // we have to remove the last whitespace as the if statement
    // in the loop would be to expensive
    resp.setLength(resp.length - 1)

    resp.toString
  }