From 033ea1bde11210f7f4b450269b1fb0522e09eddf Mon Sep 17 00:00:00 2001 From: Artyom Sayadyan Date: Thu, 7 Dec 2023 07:07:12 +0300 Subject: [PATCH] NODE-2630 Improved estimation of caches script (#3920) --- node/src/main/scala/com/wavesplatform/database/Caches.scala | 5 ++++- project/Dependencies.scala | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/node/src/main/scala/com/wavesplatform/database/Caches.scala b/node/src/main/scala/com/wavesplatform/database/Caches.scala index 08b299029a..73f3372376 100644 --- a/node/src/main/scala/com/wavesplatform/database/Caches.scala +++ b/node/src/main/scala/com/wavesplatform/database/Caches.scala @@ -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 @@ -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) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 75ed55e7d8..3a65312404 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -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, @@ -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,