Skip to content

Commit

Permalink
Merge pull request #368 from ergoplatform/fixing-bench
Browse files Browse the repository at this point in the history
Fixing applying blocks to nvh bench
  • Loading branch information
catena2w authored Jul 18, 2018
2 parents 176292d + e47b0f1 commit 228c2c1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 102 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ scala:
- 2.12.3
script:
- sbt clean coverage test coverageReport
- sbt bench:compile
# These directories are cached to S3 at the end of the build
cache:
directories:
Expand Down
70 changes: 0 additions & 70 deletions src/bench/resources/application.conf

This file was deleted.

22 changes: 14 additions & 8 deletions src/bench/scala/org/ergoplatform/bench/BenchActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package org.ergoplatform.bench

import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import org.ergoplatform.bench.protocol.Start
import org.ergoplatform.modifiers.ErgoPersistentModifier
import org.ergoplatform.modifiers.{ErgoFullBlock, ErgoPersistentModifier}
import org.ergoplatform.nodeView.state.StateType
import scorex.core.network.NodeViewSynchronizer.ReceivableMessages.SemanticallySuccessfulModifier
import scorex.core.utils.ScorexLogging

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
import scala.language.postfixOps

class BenchActor(threshold: Int) extends Actor with ScorexLogging {
class BenchActor(threshold: Int, state: StateType) extends Actor with ScorexLogging {

implicit val ec: ExecutionContext = context.dispatcher

Expand All @@ -19,10 +21,11 @@ class BenchActor(threshold: Int) extends Actor with ScorexLogging {

val timeout = 2 hours

val fileName = "target/bench/result"

val fileName = s"target/bench/result_${state.stateTypeName}"

override def preStart(): Unit = {
context.system.eventStream.subscribe(self, classOf[SemanticallySuccessfulModifier[ErgoPersistentModifier]])
context.system.eventStream.subscribe(self, classOf[SemanticallySuccessfulModifier[_]])
context.system.scheduler.scheduleOnce(timeout, self, BenchActor.Timeout)

}
Expand All @@ -31,8 +34,9 @@ class BenchActor(threshold: Int) extends Actor with ScorexLogging {
case Start =>
start = System.currentTimeMillis()
log.info(s"start is $start")
case _: SemanticallySuccessfulModifier[ErgoPersistentModifier] => self ! "increase"
case "increase" =>
case SemanticallySuccessfulModifier(fb: ErgoFullBlock) =>
self ! BenchActor.Inc
case BenchActor.Inc =>
counter += 1
if (counter % 100 == 0 ) {log.error(s"counter is $counter")}
if (counter >= threshold) {
Expand All @@ -51,9 +55,11 @@ class BenchActor(threshold: Int) extends Actor with ScorexLogging {
}

object BenchActor {
def apply(threshold: Int)(implicit ac: ActorSystem): ActorRef =
ac.actorOf(Props.apply(classOf[BenchActor], threshold))
def apply(threshold: Int, state: StateType)(implicit ac: ActorSystem): ActorRef =
ac.actorOf(Props.apply(classOf[BenchActor], threshold, state))

case object Timeout

case object Inc
}

26 changes: 16 additions & 10 deletions src/bench/scala/org/ergoplatform/bench/BenchRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ import javax.net.ssl.HttpsURLConnection
import org.ergoplatform.bench.misc.ModifierWriter
import org.ergoplatform.bench.protocol.Start
import org.ergoplatform.mining.EquihashPowScheme
import org.ergoplatform.mining.emission.CoinsEmission
import org.ergoplatform.modifiers.ErgoPersistentModifier
import org.ergoplatform.modifiers.history.Header
import org.ergoplatform.nodeView.ErgoNodeViewRef
import org.ergoplatform.nodeView.history.ErgoHistory
import org.ergoplatform.nodeView.history.storage.modifierprocessors.{FullBlockPruningProcessor, ToDownloadProcessor}
import org.ergoplatform.nodeView.mempool.ErgoMemPool
import org.ergoplatform.nodeView.state.UtxoState
import org.ergoplatform.nodeView.state.{ErgoState, StateType, UtxoState}
import org.ergoplatform.nodeView.wallet.ErgoWallet
import org.ergoplatform.settings.{ChainSettings, ErgoSettings}
import org.ergoplatform.settings.{ChainSettings, ErgoSettings, MonetarySettings}
import scorex.core.NodeViewHolder.ReceivableMessages.{GetDataFromCurrentView, LocallyGeneratedModifier}
import scorex.core.utils.{NetworkTimeProvider, NetworkTimeProviderSettings, ScorexLogging}

import scala.concurrent.ExecutionContextExecutor
import scala.concurrent.duration._
import scala.language.postfixOps

object BenchRunner extends ScorexLogging {

Expand All @@ -36,32 +38,36 @@ object BenchRunner extends ScorexLogging {

val threshold = args.headOption.getOrElse("1000").toInt
val fileName = args.lift(1).get
val isUtxo = args.lift(2).isEmpty

val benchRef = BenchActor(threshold)
val state = if (isUtxo) StateType.Utxo else StateType.Digest

val benchRef = BenchActor(threshold, state)
val userDir = TempDir.createTempDir

log.info(s"User dir is $userDir")
log.info("Starting benchmark.")

lazy val ergoSettings: ErgoSettings = ErgoSettings.read(None).copy(
directory = userDir.getAbsolutePath,
chainSettings = ChainSettings(1 minute, 1, 100, new EquihashPowScheme(96.toChar, 5.toChar))
)
val settings = ErgoSettings.read(None)
val nodeSettings = settings.nodeSettings.copy(stateType = state)

lazy val ergoSettings: ErgoSettings = settings
.copy(directory = userDir.getAbsolutePath, nodeSettings = nodeSettings)

log.info(s"Setting that being used:")
log.info(s"$ergoSettings")


val ce = new CoinsEmission(ergoSettings.chainSettings.monetary)
val ntpSettings = NetworkTimeProviderSettings("pool.ntp.org", 30 minutes, 30 seconds)
val timeProvider = new NetworkTimeProvider(ntpSettings)

val nodeViewHolderRef: ActorRef = ErgoNodeViewRef(ergoSettings, timeProvider)
val nodeViewHolderRef: ActorRef = ErgoNodeViewRef(ergoSettings, timeProvider, ce)

/**
* It's a hack to set minimalFullBlockHeightVar to 0, cause in our case we are considering
* only locally pre-generated modifiers.
*/
nodeViewHolderRef ! GetDataFromCurrentView[ErgoHistory, UtxoState, ErgoWallet, ErgoMemPool, Unit]{ v =>
nodeViewHolderRef ! GetDataFromCurrentView[ErgoHistory, ErgoState[_], ErgoWallet, ErgoMemPool, Unit]{ v =>
import scala.reflect.runtime.{universe => ru}
val runtimeMirror = ru.runtimeMirror(getClass.getClassLoader)
val procInstance = runtimeMirror.reflect(v.history.asInstanceOf[ToDownloadProcessor])
Expand Down
25 changes: 14 additions & 11 deletions src/bench/scala/org/ergoplatform/bench/CrawlerRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import akka.actor.{ActorRef, Props}
import org.ergoplatform.api.{BlocksApiRoute, InfoRoute, TransactionsApiRoute}
import org.ergoplatform.bench.misc.CrawlerConfig
import org.ergoplatform.local.{ErgoMinerRef, ErgoStatsCollectorRef}
import org.ergoplatform.mining.emission.CoinsEmission
import org.ergoplatform.modifiers.ErgoPersistentModifier
import org.ergoplatform.modifiers.mempool.AnyoneCanSpendTransaction
import org.ergoplatform.modifiers.mempool.proposition.AnyoneCanSpendProposition
import org.ergoplatform.modifiers.mempool.ErgoTransaction
import org.ergoplatform.network.ErgoNodeViewSynchronizer
import org.ergoplatform.nodeView.history.ErgoSyncInfoMessageSpec
import org.ergoplatform.nodeView.{ErgoNodeViewHolder, ErgoNodeViewRef, ErgoReadersHolderRef}
import org.ergoplatform.settings.{Algos, ErgoSettings}
import scorex.core.api.http.{ApiRoute, PeersApiRoute, UtilsApiRoute}
import scorex.core.app.Application
import scorex.core.network.PeerFeature
import scorex.core.network.message.MessageSpec
import scorex.core.settings.ScorexSettings

Expand All @@ -21,8 +22,7 @@ import scala.io.Source

class CrawlerRunner(args: Array[String]) extends Application {

override type P = AnyoneCanSpendProposition.type
override type TX = AnyoneCanSpendTransaction
override type TX = ErgoTransaction
override type PMOD = ErgoPersistentModifier
override type NVHT = ErgoNodeViewHolder[_]

Expand All @@ -35,20 +35,23 @@ class CrawlerRunner(args: Array[String]) extends Application {
log.info(s"Temp dir is ${tempDir.getAbsolutePath}")
log.info(s"Config is $benchConfig")

override protected lazy val features: Seq[PeerFeature] = Seq()

implicit val ec: ExecutionContextExecutor = actorSystem.dispatcher

lazy val ergoSettings: ErgoSettings = ErgoSettings.read(cfgPath)

override implicit lazy val settings: ScorexSettings = ergoSettings.scorexSettings
lazy val emission = new CoinsEmission(ergoSettings.chainSettings.monetary)

val crawlerRef = actorSystem.actorOf(Props.apply(classOf[CrawlerActor], benchConfig))
override implicit lazy val settings: ScorexSettings = ergoSettings.scorexSettings

override protected lazy val additionalMessageSpecs: Seq[MessageSpec[_]] = Seq(ErgoSyncInfoMessageSpec)
override val nodeViewHolderRef: ActorRef = ErgoNodeViewRef(ergoSettings, timeProvider)
override val nodeViewHolderRef: ActorRef = ErgoNodeViewRef(ergoSettings, timeProvider, emission)

val readersHolderRef: ActorRef = ErgoReadersHolderRef(nodeViewHolderRef)

val minerRef: ActorRef = ErgoMinerRef(ergoSettings, nodeViewHolderRef, readersHolderRef, timeProvider)

val minerRef: ActorRef = ErgoMinerRef(ergoSettings, nodeViewHolderRef, readersHolderRef, timeProvider, emission)

val statsCollectorRef: ActorRef = ErgoStatsCollectorRef(nodeViewHolderRef, peerManagerRef, ergoSettings, timeProvider)

Expand All @@ -61,9 +64,9 @@ class CrawlerRunner(args: Array[String]) extends Application {

override val swaggerConfig: String = Source.fromResource("api/openapi.yaml").getLines.mkString("\n")

override val nodeViewSynchronizer: ActorRef = ErgoNodeViewSynchronizer(
networkControllerRef,
nodeViewHolderRef, ErgoSyncInfoMessageSpec, settings.network, timeProvider)
override val nodeViewSynchronizer: ActorRef =
ErgoNodeViewSynchronizer(networkControllerRef, nodeViewHolderRef, ErgoSyncInfoMessageSpec,
settings.network, timeProvider)

}

Expand Down
2 changes: 2 additions & 0 deletions src/bench/scala/org/ergoplatform/bench/HistoryExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import org.ergoplatform.settings.ErgoSettings
import scorex.core.settings.ScorexSettings
import scorex.core.utils.{NetworkTimeProvider, ScorexLogging}

import scala.concurrent.ExecutionContext.Implicits.global

object HistoryExtractor extends ScorexLogging {

def main(args: Array[String]): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ object ModifierWriter {
mod <- modifierSerializers(typeId).parseBytes(bytes).toOption
} yield mod

private def readModId(implicit fis: InputStream): Option[ModifierTypeId] =
Some(ModifierTypeId @@ fis.read().toByte).filterNot(_ == -1)
private def readModId(implicit fis: InputStream): Option[ModifierTypeId] = {
val int = fis.read()
if (int == -1) { None } else { Some(ModifierTypeId @@ int.toByte) }
}

private def readLength(implicit fis: InputStream): Option[Int] =
Some(Stream.continually(fis.read().toByte).take(4).toArray).filterNot(_.contains(-1: Byte)).map(Ints.fromByteArray)
Some(Stream.continually(fis.read().toByte).take(4).toArray).map(Ints.fromByteArray)

private def readBytes(length: Int)(implicit fis: InputStream): Option[Array[Byte]] =
Some(Stream.continually(fis.read().toByte).take(length).toArray)
Expand Down

0 comments on commit 228c2c1

Please sign in to comment.