mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
[CORDA-2431] - Reduce memory footprint of classpath scanning (#4576)
* Reduce memory footprint of classpath scanning * Close scan result in the end
This commit is contained in:
parent
d1575b4031
commit
f51cfc34bf
@ -1,8 +1,6 @@
|
|||||||
package net.corda.core.internal
|
package net.corda.core.internal
|
||||||
|
|
||||||
import io.github.classgraph.ClassGraph
|
import io.github.classgraph.ClassGraph
|
||||||
import net.corda.core.CordaInternal
|
|
||||||
import net.corda.core.DeleteForDJVM
|
|
||||||
import net.corda.core.StubOutForDJVM
|
import net.corda.core.StubOutForDJVM
|
||||||
import kotlin.reflect.full.createInstance
|
import kotlin.reflect.full.createInstance
|
||||||
|
|
||||||
@ -21,11 +19,13 @@ import kotlin.reflect.full.createInstance
|
|||||||
@StubOutForDJVM
|
@StubOutForDJVM
|
||||||
fun <T: Any> loadClassesImplementing(classloader: ClassLoader, clazz: Class<T>): Set<T> {
|
fun <T: Any> loadClassesImplementing(classloader: ClassLoader, clazz: Class<T>): Set<T> {
|
||||||
return ClassGraph().addClassLoader(classloader)
|
return ClassGraph().addClassLoader(classloader)
|
||||||
.enableAllInfo()
|
.enableClassInfo()
|
||||||
.scan()
|
.scan()
|
||||||
.getClassesImplementing(clazz.name)
|
.use {
|
||||||
.filterNot { it.isAbstract }
|
it.getClassesImplementing(clazz.name)
|
||||||
.mapNotNull { classloader.loadClass(it.name).asSubclass(clazz) }
|
.filterNot { it.isAbstract }
|
||||||
.map { it.kotlin.objectInstance ?: it.kotlin.createInstance() }
|
.mapNotNull { classloader.loadClass(it.name).asSubclass(clazz) }
|
||||||
.toSet()
|
.map { it.kotlin.objectInstance ?: it.kotlin.createInstance() }
|
||||||
|
.toSet()
|
||||||
|
}
|
||||||
}
|
}
|
@ -23,7 +23,7 @@ class AttachmentDemoTest {
|
|||||||
startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = demoUser, maximumHeapSize = "1g"),
|
startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = demoUser, maximumHeapSize = "1g"),
|
||||||
startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = demoUser, maximumHeapSize = "1g")
|
startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = demoUser, maximumHeapSize = "1g")
|
||||||
).map { it.getOrThrow() }
|
).map { it.getOrThrow() }
|
||||||
val webserverHandle = startWebserver(nodeB, "1g").getOrThrow()
|
val webserverHandle = startWebserver(nodeB).getOrThrow()
|
||||||
|
|
||||||
val senderThread = supplyAsync {
|
val senderThread = supplyAsync {
|
||||||
CordaRPCClient(nodeA.rpcAddress).start(demoUser[0].username, demoUser[0].password).use {
|
CordaRPCClient(nodeA.rpcAddress).start(demoUser[0].username, demoUser[0].password).use {
|
||||||
|
@ -63,7 +63,7 @@ object FixingFlow {
|
|||||||
|
|
||||||
// We set the transaction's time-window: it may be that none of the contracts need this!
|
// We set the transaction's time-window: it may be that none of the contracts need this!
|
||||||
// But it can't hurt to have one.
|
// But it can't hurt to have one.
|
||||||
ptx.setTimeWindow(serviceHub.clock.instant(), 60.seconds)
|
ptx.setTimeWindow(serviceHub.clock.instant(), 30.seconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
|
@ -54,14 +54,13 @@ class SimmValuationTest {
|
|||||||
assertThat(logConfigFile).isRegularFile()
|
assertThat(logConfigFile).isRegularFile()
|
||||||
driver(DriverParameters(isDebug = true,
|
driver(DriverParameters(isDebug = true,
|
||||||
cordappsForAllNodes = listOf(findCordapp("net.corda.vega.flows"), findCordapp("net.corda.vega.contracts"), findCordapp("net.corda.confidential")) + FINANCE_CORDAPPS,
|
cordappsForAllNodes = listOf(findCordapp("net.corda.vega.flows"), findCordapp("net.corda.vega.contracts"), findCordapp("net.corda.confidential")) + FINANCE_CORDAPPS,
|
||||||
systemProperties = mapOf("log4j.configurationFile" to logConfigFile.toString()),
|
systemProperties = mapOf("log4j.configurationFile" to logConfigFile.toString()))
|
||||||
notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, maximumHeapSize = "1g")))
|
|
||||||
) {
|
) {
|
||||||
val nodeAFuture = startNode(providedName = nodeALegalName, maximumHeapSize = "1g")
|
val nodeAFuture = startNode(providedName = nodeALegalName)
|
||||||
val nodeBFuture = startNode(providedName = nodeBLegalName, maximumHeapSize = "1g")
|
val nodeBFuture = startNode(providedName = nodeBLegalName)
|
||||||
val (nodeA, nodeB) = listOf(nodeAFuture, nodeBFuture).map { it.getOrThrow() }
|
val (nodeA, nodeB) = listOf(nodeAFuture, nodeBFuture).map { it.getOrThrow() }
|
||||||
val nodeAWebServerFuture = startWebserver(nodeA, "1g")
|
val nodeAWebServerFuture = startWebserver(nodeA)
|
||||||
val nodeBWebServerFuture = startWebserver(nodeB, "1g")
|
val nodeBWebServerFuture = startWebserver(nodeB)
|
||||||
val nodeAApi = HttpApi.fromHostAndPort(nodeAWebServerFuture.getOrThrow().listenAddress, "api/simmvaluationdemo")
|
val nodeAApi = HttpApi.fromHostAndPort(nodeAWebServerFuture.getOrThrow().listenAddress, "api/simmvaluationdemo")
|
||||||
val nodeBApi = HttpApi.fromHostAndPort(nodeBWebServerFuture.getOrThrow().listenAddress, "api/simmvaluationdemo")
|
val nodeBApi = HttpApi.fromHostAndPort(nodeBWebServerFuture.getOrThrow().listenAddress, "api/simmvaluationdemo")
|
||||||
val nodeBParty = getPartyWithName(nodeAApi, nodeBLegalName)
|
val nodeBParty = getPartyWithName(nodeAApi, nodeBLegalName)
|
||||||
|
@ -37,13 +37,12 @@ class TraderDemoTest {
|
|||||||
driver(DriverParameters(
|
driver(DriverParameters(
|
||||||
startNodesInProcess = true,
|
startNodesInProcess = true,
|
||||||
inMemoryDB = false,
|
inMemoryDB = false,
|
||||||
cordappsForAllNodes = FINANCE_CORDAPPS + TestCordapp.findCordapp("net.corda.traderdemo"),
|
cordappsForAllNodes = FINANCE_CORDAPPS + TestCordapp.findCordapp("net.corda.traderdemo")
|
||||||
notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, maximumHeapSize = "1g"))
|
|
||||||
)) {
|
)) {
|
||||||
val (nodeA, nodeB, bankNode) = listOf(
|
val (nodeA, nodeB, bankNode) = listOf(
|
||||||
startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = listOf(demoUser), maximumHeapSize = "1g"),
|
startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = listOf(demoUser)),
|
||||||
startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = listOf(demoUser), maximumHeapSize = "1g"),
|
startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = listOf(demoUser)),
|
||||||
startNode(providedName = BOC_NAME, rpcUsers = listOf(bankUser), maximumHeapSize = "1g")
|
startNode(providedName = BOC_NAME, rpcUsers = listOf(bankUser))
|
||||||
).map { (it.getOrThrow() as InProcess) }
|
).map { (it.getOrThrow() as InProcess) }
|
||||||
|
|
||||||
val (nodeARpc, nodeBRpc) = listOf(nodeA, nodeB).map {
|
val (nodeARpc, nodeBRpc) = listOf(nodeA, nodeB).map {
|
||||||
|
@ -31,7 +31,7 @@ class WebserverDriverTests {
|
|||||||
fun `starting a node and independent web server works`() {
|
fun `starting a node and independent web server works`() {
|
||||||
val addr = driver(DriverParameters(notarySpecs = emptyList())) {
|
val addr = driver(DriverParameters(notarySpecs = emptyList())) {
|
||||||
val node = startNode(providedName = DUMMY_BANK_A_NAME).getOrThrow()
|
val node = startNode(providedName = DUMMY_BANK_A_NAME).getOrThrow()
|
||||||
val webserverHandle = startWebserver(node, "512m").getOrThrow()
|
val webserverHandle = startWebserver(node).getOrThrow()
|
||||||
webserverMustBeUp(webserverHandle)
|
webserverMustBeUp(webserverHandle)
|
||||||
webserverHandle.listenAddress
|
webserverHandle.listenAddress
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user