remove dev mode memory freeing code

cats
Thibault Duplessis 2020-08-12 09:27:35 +02:00
parent c5da5010a4
commit 4d28b04c8a
5 changed files with 24 additions and 80 deletions

View File

@ -31,8 +31,6 @@ final class LilaComponents(ctx: ApplicationLoader.Context)
s"lila $appVersionCommit $appVersionDate / java ${java}, memory: ${mem}MB"
}
lila.mon.start(configuration.get[Boolean]("kamon.enabled"))
import _root_.controllers._
// we want to use the legacy session cookie baker

View File

@ -2,17 +2,16 @@ package lila.app
import akka.actor._
import com.softwaremill.macwire._
import lila.memo.SettingStore.Strings._
import lila.memo.SettingStore.UserIds._
import play.api.libs.ws.StandaloneWSClient
import play.api.mvc.{ ControllerComponents, SessionCookieBaker }
import play.api.{ Configuration, Environment, Mode }
import play.api.{ Configuration, Environment }
import scala.concurrent.duration._
import scala.concurrent.{ ExecutionContext, Future }
import lila.common.config._
import lila.common.{ Bus, Lilakka, Strings }
import lila.common.UserIds
import lila.common.{ Bus, Strings, UserIds }
import lila.memo.SettingStore.Strings._
import lila.memo.SettingStore.UserIds._
final class Env(
val config: Configuration,
@ -274,14 +273,4 @@ final class EnvBoot(
}
templating.Environment setEnv env
// free memory for reload workflow
if (mode == Mode.Dev)
Lilakka.shutdown(shutdown, _.PhaseServiceStop, "Freeing dev memory") { () =>
Future {
templating.Environment.destroy()
lila.common.Bus.destroy()
lila.mon.destroy()
}
}
}

View File

@ -29,7 +29,6 @@ object Environment
// requires injecting all the templates!!
private var envVar: Option[Env] = None
def setEnv(e: Env) = { envVar = Some(e) }
def destroy() = { envVar = None }
def env: Env = envVar.get
type FormWithCaptcha = (play.api.data.Form[_], lila.common.Captcha)

View File

@ -65,9 +65,8 @@ object Bus {
publish = (tellable, event) => tellable ! event
)
def keys = bus.keys
def size = bus.size
def destroy() = bus.destroy()
def keys = bus.keys
def size = bus.size
case class AskTimeout(message: String) extends lila.base.LilaException
}
@ -80,27 +79,24 @@ final private class EventBus[Event, Channel, Subscriber](
import java.util.concurrent.ConcurrentHashMap
private val entries = new ConcurrentHashMap[Channel, Set[Subscriber]](initialCapacity)
private var alive = true
def subscribe(subscriber: Subscriber, channel: Channel): Unit =
if (alive)
entries.compute(
channel,
(_: Channel, subs: Set[Subscriber]) => {
Option(subs).fold(Set(subscriber))(_ + subscriber)
}
)
entries.compute(
channel,
(_: Channel, subs: Set[Subscriber]) => {
Option(subs).fold(Set(subscriber))(_ + subscriber)
}
)
def unsubscribe(subscriber: Subscriber, channel: Channel): Unit =
if (alive)
entries.computeIfPresent(
channel,
(_: Channel, subs: Set[Subscriber]) => {
val newSubs = subs - subscriber
if (newSubs.isEmpty) null
else newSubs
}
)
entries.computeIfPresent(
channel,
(_: Channel, subs: Set[Subscriber]) => {
val newSubs = subs - subscriber
if (newSubs.isEmpty) null
else newSubs
}
)
def publish(event: Event, channel: Channel): Unit =
Option(entries get channel) foreach {
@ -112,8 +108,4 @@ final private class EventBus[Event, Channel, Subscriber](
def keys: Set[Channel] = entries.keySet.asScala.toSet
def size = entries.size
def sizeOf(channel: Channel) = Option(entries get channel).fold(0)(_.size)
def destroy() = {
alive = false
entries.clear()
}
}

View File

@ -577,18 +577,10 @@ object mon {
type TimerPath = lila.mon.type => Timer
type CounterPath = lila.mon.type => Counter
private var backend: kamon.metric.MetricBuilding = _
def start(enabled: Boolean): Unit = {
backend = if (enabled) kamon.Kamon else new KamonStub
}
def destroy(): Unit = {
backend = null
}
private def timer(name: String) = backend.timer(name)
private def gauge(name: String) = backend.gauge(name)
private def counter(name: String) = backend.counter(name)
private def histogram(name: String) = backend.histogram(name)
private def timer(name: String) = kamon.Kamon.timer(name)
private def gauge(name: String) = kamon.Kamon.gauge(name)
private def counter(name: String) = kamon.Kamon.counter(name)
private def histogram(name: String) = kamon.Kamon.histogram(name)
private def future(name: String) = (success: Boolean) => timer(name).withTag("success", successTag(success))
private def future(name: String, segment: String) =
@ -603,29 +595,3 @@ object mon {
implicit def mapToTags(m: Map[String, Any]): TagSet = TagSet from m
}
// because using kamon.Kamon in dev mode
// causes leaks between reloads
final class KamonStub extends kamon.metric.MetricBuilding {
import java.util.concurrent.{ Executors, ThreadFactory }
import java.util.concurrent.atomic.AtomicInteger
protected val registry = new kamon.metric.MetricRegistry(
com.typesafe.config.ConfigFactory.load(kamon.ClassLoading.classLoader()),
Executors.newScheduledThreadPool(
1,
new ThreadFactory {
val count = new AtomicInteger()
val defaultFactory = Executors.defaultThreadFactory()
override def newThread(r: Runnable): Thread = {
val thread = defaultFactory.newThread(r)
thread.setName("kamon-scheduler-" + count.incrementAndGet().toString)
thread.setDaemon(true)
thread
}
}
),
new kamon.util.Clock.Anchored()
)
}