Skip to content

Commit

Permalink
NODE-2630 Improved estimation of caches script (#3920)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrtm000 authored Dec 7, 2023
1 parent a518c18 commit 033ea1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion node/src/main/scala/com/wavesplatform/database/Caches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves}
import com.wavesplatform.transaction.{Asset, DiscardedBlocks, Transaction}
import com.wavesplatform.utils.ObservedLoadingCache
import monix.reactive.Observer
import org.ehcache.sizeof.SizeOf

import java.{lang, util}
import scala.collection.immutable.VectorMap
Expand Down Expand Up @@ -127,11 +128,13 @@ abstract class Caches extends Blockchain with Storage {
VolumeAndFee(curVf.volume, curVf.fee)
}

private val objectWeigher = SizeOf.newInstance()

private val scriptCache: LoadingCache[Address, Option[AccountScriptInfo]] =
CacheBuilder
.newBuilder()
.maximumWeight(128 << 20)
.weigher((_: Address, asi: Option[AccountScriptInfo]) => asi.map(_.script.bytes().size).getOrElse(0))
.weigher((_: Address, asi: Option[AccountScriptInfo]) => asi.map(s => objectWeigher.deepSizeOf(s).toInt).getOrElse(0))
.recordStats()
.build(new CacheLoader[Address, Option[AccountScriptInfo]] {
override def load(key: Address): Option[AccountScriptInfo] = loadScript(key)
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ object Dependencies {
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.5",
"eu.timepit" %% "refined" % "0.11.0" exclude ("org.scala-lang.modules", "scala-xml_2.13"),
"com.esaulpaugh" % "headlong" % "10.0.1",
"org.ehcache" % "sizeof" % "0.4.3", // Weighing caches
web3jModule("abi"),
akkaModule("testkit") % Test,
akkaHttpModule("akka-http-testkit") % Test,
Expand Down Expand Up @@ -164,7 +165,6 @@ object Dependencies {
// "io.netty" % "netty-transport-native-epoll" % "4.1.79.Final" classifier "linux-x86_64",
"com.github.ben-manes.caffeine" % "caffeine" % "3.1.8",
"net.logstash.logback" % "logstash-logback-encoder" % "7.4" % Runtime,
"org.ehcache" % "sizeof" % "0.4.3", // Weighing caches
kamonModule("caffeine"),
kamonModule("prometheus"),
sttp3,
Expand Down

0 comments on commit 033ea1b

Please sign in to comment.