Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NODE-2630 Improved estimation of cached scripts size #3920

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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