Reducing overhead of rpc callbacks by 1) subsampling cancelled status check (had severe impact), and 2) using buffered remote message streams (had less but still noticeable impact)

This commit is contained in:
Ilya Chernikov
2015-10-07 12:56:45 +02:00
parent e27abe2f03
commit 6a7c5e1576
2 changed files with 23 additions and 7 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.rmi.*
import java.io.BufferedOutputStream
import java.io.PrintStream
import java.rmi.NoSuchObjectException
import java.rmi.registry.Registry
@@ -130,12 +131,18 @@ class CompileServiceImpl(
private fun doCompile(args: Array<out String>, compilerMessagesStreamProxy: RemoteOutputStream, serviceOutputStreamProxy: RemoteOutputStream, body: (PrintStream, Profiler) -> ExitCode): Int =
ifAlive {
val rpcProfiler = if (daemonOptions.reportPerf) WallAndThreadTotalProfiler() else DummyProfiler()
val compilerMessagesStream = PrintStream(RemoteOutputStreamClient(compilerMessagesStreamProxy, rpcProfiler))
val serviceOutputStream = PrintStream(RemoteOutputStreamClient(serviceOutputStreamProxy, rpcProfiler))
checkedCompile(args, serviceOutputStream, rpcProfiler) {
val res = body( compilerMessagesStream, rpcProfiler).code
_lastUsedSeconds = nowSeconds()
res
val compilerMessagesStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(compilerMessagesStreamProxy, rpcProfiler), 4096))
val serviceOutputStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(serviceOutputStreamProxy, rpcProfiler), 4096))
try {
checkedCompile(args, serviceOutputStream, rpcProfiler) {
val res = body(compilerMessagesStream, rpcProfiler).code
_lastUsedSeconds = nowSeconds()
res
}
}
finally {
serviceOutputStream.flush()
compilerMessagesStream.flush()
}
}
@@ -20,10 +20,19 @@ import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.rmi.CompilerCallbackServicesFacade
import org.jetbrains.kotlin.rmi.DummyProfiler
import org.jetbrains.kotlin.rmi.Profiler
import java.util.concurrent.TimeUnit
val CANCELED_STATUS_CHECK_THRESHOLD_NS = TimeUnit.MILLISECONDS.toNanos(100)
class RemoteCompilationCanceledStatusClient(val facade: CompilerCallbackServicesFacade, val profiler: Profiler = DummyProfiler()): CompilationCanceledStatus {
@Volatile var lastChecked: Long = System.nanoTime()
override fun checkCanceled() {
profiler.withMeasure(this) { facade.compilationCanceledStatus_checkCanceled() }
val curNanos = System.nanoTime()
if (curNanos - lastChecked > CANCELED_STATUS_CHECK_THRESHOLD_NS) {
profiler.withMeasure(this) {
facade.compilationCanceledStatus_checkCanceled()
}
lastChecked = curNanos
}
}
}