Skip to content

Commit f93f4d2

Browse files
authored
Add num_users_active property to Context and Benchmark records (#356)
* Add num_users_active property to Context and Benchmark records * Display the number of active users * Comment cleanup
1 parent 6f9894b commit f93f4d2

File tree

8 files changed

+45
-57
lines changed

8 files changed

+45
-57
lines changed

tulip-runtime/src/main/java/io/github/wfouche/tulip/api/TulipApi.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ public static boolean isUtf8Terminal() {
123123
}
124124
}
125125

126+
/**
127+
* Create a JSON string containing JVM runtime information
128+
*
129+
* @return JSON String
130+
*/
126131
public static String getJavaInformation() {
127132
var s = "{ \"jvm.system.properties\": {";
128133
s += "\"java.vendor\"" + ":\"" + System.getProperty("java.vendor") + "\", ";

tulip-runtime/src/main/kotlin/io/github/wfouche/tulip/core/ActionStats.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class ActionStats {
4949
durationMillis: Int,
5050
testCase: TestProfile,
5151
indexTestCase: Int,
52-
indexUserProfile: Int,
5352
queueLength: Int,
5453
tsBegin: String,
5554
tsEnd: String,
@@ -68,7 +67,6 @@ class ActionStats {
6867
r.testPhase = testPhase
6968

7069
r.testId = indexTestCase
71-
r.indexUserProfile = indexUserProfile
7270
r.queueLength = queueLength
7371

7472
r.numActions = numActions

tulip-runtime/src/main/kotlin/io/github/wfouche/tulip/core/ActionSummary.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ data class ActionSummary(
1010
var testName: String = "",
1111
var testPhase: String = "",
1212
var testId: Int = 0,
13-
var indexUserProfile: Int = 0,
1413
var queueLength: Int = 0,
1514
var numActions: Int = 0,
1615
var numSuccess: Int = 0,
@@ -27,9 +26,6 @@ data class ActionSummary(
2726
var maxWt: Double = 0.0,
2827
var pk: List<Double> = mutableListOf(),
2928
var pv: List<Double> = mutableListOf(),
30-
31-
// var avgCpuSystem: Double = 0.0,
32-
// var avgCpuProcess: Double = 0.0
3329
var processCpuTime: Long = 0,
3430
var processCpuCores: Double = 0.0,
3531
var processCpuUtilization: Double = 0.0,

tulip-runtime/src/main/kotlin/io/github/wfouche/tulip/core/DataCollector.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ object DataCollector {
3636
durationMillis,
3737
testCase,
3838
indexTestCase,
39-
indexUserProfile,
4039
queueLength,
4140
tsBegin,
4241
tsEnd,
@@ -53,7 +52,6 @@ object DataCollector {
5352
durationMillis,
5453
testCase,
5554
indexTestCase,
56-
indexUserProfile,
5755
queueLength,
5856
tsBegin,
5957
tsEnd,

tulip-runtime/src/main/kotlin/io/github/wfouche/tulip/core/RuntimeContext.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import kotlinx.serialization.json.JsonPrimitive
55
data class RuntimeContext(
66
val name: String = "",
77
val numUsers: Int = 0,
8+
val numUsersActive: Int = 0,
89
val numThreads: Int = 0,
910
val userParams: Map<String, JsonPrimitive> = mapOf(),
1011
)

tulip-runtime/src/main/kotlin/io/github/wfouche/tulip/core/TestProfile.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ data class TestProfile(
2929
//
3030
// This value represents the "L" in Little's Law (equation)
3131
//
32-
val queueLengths: List<Int> = listOf(0),
32+
val numUsersActive: Int = 0,
3333

3434
// List of percentile values to report on.
3535
val percentiles: List<Double> = listOf(50.0, 75.0, 90.0, 95.0, 99.0),

tulip-runtime/src/main/kotlin/io/github/wfouche/tulip/core/Tulip.kt

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import java.time.format.DateTimeFormatter
2020
import java.util.concurrent.LinkedBlockingQueue as BlockingQueue
2121
import java.util.concurrent.ThreadLocalRandom
2222
import java.util.concurrent.TimeUnit
23-
import kotlin.math.abs
2423
import kotlin.system.exitProcess
2524
import kotlinx.serialization.SerialName
2625
import kotlinx.serialization.Serializable
@@ -207,6 +206,7 @@ private val g_tests = mutableListOf<TestProfile>()
207206
data class ConfigContext(
208207
val enabled: Boolean = false,
209208
@SerialName("num_users") val numUsers: Int = 0,
209+
@SerialName("num_users_active") val numUsersActive: Int = USER_THREAD_QSIZE,
210210
@SerialName("num_threads") val numThreads: Int = 0,
211211
@SerialName("user_params") val userParams: Map<String, JsonPrimitive> = mapOf(),
212212
)
@@ -229,7 +229,7 @@ data class ConfigTest(
229229
@SerialName("aps_rate") val throughputRate: Double = 0.0,
230230
@SerialName("aps_rate_step_change") val throughputRateStepChange: Double = 0.0,
231231
@SerialName("aps_rate_step_count") val throughputRateStepCount: Int = 1,
232-
@SerialName("worker_thread_queue_size") val workInProgress: Int = 0,
232+
@SerialName("num_users_active") val numUsersActive: Int = 0,
233233
@SerialName("scenario_actions") val actions: List<ConfigAction> = listOf(),
234234
@SerialName("scenario_workflow") val workflow: String = "",
235235
)
@@ -301,7 +301,7 @@ fun initConfig(text: String): String {
301301
// println("${k}")
302302
val e = entry.value
303303
if (e.enabled) {
304-
val v = RuntimeContext(k, e.numUsers, e.numThreads, e.userParams)
304+
val v = RuntimeContext(k, e.numUsers, e.numUsersActive, e.numThreads, e.userParams)
305305
g_contexts.add(v)
306306
}
307307
}
@@ -323,7 +323,7 @@ fun initConfig(text: String): String {
323323
arrivalRate = e.throughputRate,
324324
arrivalRateStepChange = e.throughputRateStepChange,
325325
arrivalRateStepCount = e.throughputRateStepCount,
326-
queueLengths = listOf(e.workInProgress),
326+
numUsersActive = e.numUsersActive,
327327
actions =
328328
mutableListOf<Action>().apply {
329329
if (e.workflow.isEmpty()) {
@@ -392,28 +392,18 @@ val wthread_wait_stats = Histogram(histogramNumberOfSignificantValueDigits)
392392

393393
/*-------------------------------------------------------------------------*/
394394

395-
private fun getQueueLengths(context: RuntimeContext, test: TestProfile): List<Int> {
396-
val list: MutableList<Int> = mutableListOf()
397-
test.queueLengths.forEach { queueLength ->
398-
list.add(
399-
when {
400-
queueLength == 0 ->
401-
if (context.numThreads == 0) context.numUsers * USER_THREAD_QSIZE
402-
else context.numThreads * USER_THREAD_QSIZE
403-
queueLength > 0 ->
404-
if (context.numThreads == 0) context.numUsers * queueLength
405-
else context.numThreads * queueLength // Actions per Thread
406-
else -> abs(queueLength) // Actions across all Threads
407-
}
408-
)
395+
private fun getQueueLengths(context: RuntimeContext, test: TestProfile): Int {
396+
return if (test.numUsersActive != 0) {
397+
test.numUsersActive
398+
} else {
399+
context.numUsersActive
409400
}
410-
return list
411401
}
412402

413403
/*-------------------------------------------------------------------------*/
414404

415405
private fun getTest(context: RuntimeContext, test: TestProfile): TestProfile {
416-
return test.copy(queueLengths = getQueueLengths(context, test))
406+
return test.copy(numUsersActive = getQueueLengths(context, test))
417407
}
418408

419409
/*-------------------------------------------------------------------------*/
@@ -431,20 +421,12 @@ private fun createActionGenerator(list: List<Int>): Iterator<Int> {
431421

432422
/*-------------------------------------------------------------------------*/
433423

434-
private fun runTest(
435-
testCase: TestProfile,
436-
contextId: Int,
437-
indexTestCase: Int,
438-
indexUserProfile: Int,
439-
queueLength: Int,
440-
) {
424+
private fun runTest(testCase: TestProfile, contextId: Int, indexTestCase: Int, queueLength: Int) {
441425
var cpuTime: Long = 0
442426
var tsBegin = java.time.LocalDateTime.now().format(formatter)
443427
val output = mutableListOf("")
444428
output.add("======================================================================")
445-
output.add(
446-
"= [${contextId}][${indexTestCase}][${indexUserProfile}][${queueLength}] ${testCase.name} - $tsBegin"
447-
)
429+
output.add("= [${contextId}][${indexTestCase}][${queueLength}] ${testCase.name} - $tsBegin")
448430
output.add("======================================================================")
449431
Console.put(output)
450432

@@ -574,7 +556,7 @@ private fun runTest(
574556
durationMillis,
575557
testCase,
576558
indexTestCase,
577-
indexUserProfile,
559+
0,
578560
queueLength,
579561
tsBegin,
580562
tsEnd,
@@ -693,7 +675,7 @@ private fun runTest(
693675
durationMillis.toInt(),
694676
testCase,
695677
indexTestCase,
696-
indexUserProfile,
678+
0,
697679
queueLength,
698680
tsBegin,
699681
tsEnd,
@@ -717,13 +699,7 @@ private fun runTest(
717699

718700
// Pre-warmup
719701
//
720-
// Since we could have 1 or more population set sizes, only perform the
721-
// start-up phase
722-
// on the first set, i.e., with index 0.
723-
//
724-
if (indexUserProfile == 0) {
725-
assignTasks(testCase.duration.startupDurationMillis, "PreWarmup", 0, 0, 0.0)
726-
}
702+
assignTasks(testCase.duration.startupDurationMillis, "PreWarmup", 0, 0, 0.0)
727703

728704
// Warmup
729705
timeMillisEnd = TimeUnit.NANOSECONDS.toMillis(System.nanoTime())
@@ -781,11 +757,14 @@ private fun runTulip(
781757
Console.put("======================================================================")
782758
Console.put("")
783759
Console.put(" NUM_USERS = $MAX_NUM_USERS")
760+
Console.put(" NUM_USERS_ACTIVE = ${context.numUsersActive}")
784761
if (MAX_NUM_THREADS == 0) {
785762
MAX_NUM_THREADS = MAX_NUM_USERS
763+
Console.put(" NUM_VIRTUAL_THREADS = $MAX_NUM_THREADS")
764+
} else {
765+
Console.put(" NUM_THREADS = $MAX_NUM_THREADS")
766+
Console.put(" NUM_USERS_PER_THREAD = ${MAX_NUM_USERS / MAX_NUM_THREADS}")
786767
}
787-
Console.put(" NUM_THREADS = $MAX_NUM_THREADS")
788-
Console.put(" NUM_USERS_PER_THREAD = ${MAX_NUM_USERS / MAX_NUM_THREADS}")
789768
if ((MAX_NUM_USERS / MAX_NUM_THREADS) * MAX_NUM_THREADS != MAX_NUM_USERS) {
790769
Console.put("")
791770
Console.put("NUM_USERS should equal n*NUM_THREADS, where n >= 1")
@@ -799,10 +778,9 @@ private fun runTulip(
799778
} else {
800779
g_workflow = workflows[x.workflow]
801780
}
802-
x.queueLengths.forEachIndexed { indexUserProfile, queueLength ->
803-
// Thread.sleep(5000)
804-
runTest(x, contextId, indexTestCase, indexUserProfile, queueLength)
805-
}
781+
val numUsersActive = x.numUsersActive
782+
// Thread.sleep(5000)
783+
runTest(x, contextId, indexTestCase, numUsersActive)
806784
g_workflow = null
807785
}
808786
}

tulip-runtime/src/main/kotlin/io/github/wfouche/tulip/core/UserThreads.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package io.github.wfouche.tulip.core
33
import io.github.wfouche.tulip.api.TulipUser
44
import java.util.concurrent.ExecutorService
55
import java.util.concurrent.Executors
6+
import kotlin.time.Clock
7+
import kotlin.time.Instant
68
import org.HdrHistogram.IntCountsHistogram
79

810
var useVirtualThreads = false
@@ -117,18 +119,28 @@ fun assignTaskToUser(task: Task) {
117119

118120
fun runtimeDonePT() {
119121
// Terminate all platform threads.
120-
userPlatformThreads!!.forEach { thread -> thread!!.tq.put(Task(status = 999)) }
122+
userPlatformThreads!!.forEach { thread ->
123+
thread!!.tq.clear()
124+
thread.tq.put(Task(status = 999))
125+
}
121126

122127
// Wait for all platform threads to exit.
123128
while (userPlatformThreads!!.map { if (it == null) 0 else 1 }.sum() > 0) {
124129
Thread.sleep(500)
125130
}
126131
}
127132

133+
fun displayTimestamp() {
134+
val now: Instant = Clock.System.now()
135+
println("Current Instant: $now")
136+
}
137+
128138
fun runtimeDoneVT() {
129139
// Terminate all virtual threads.
130-
userObjects!!.forEach { user -> user!!.tq.put(Task(status = 999)) }
131-
140+
userObjects!!.forEach { user ->
141+
user!!.tq.clear()
142+
user.tq.put(Task(status = 999))
143+
}
132144
// Wait for all virtual threads to exit.
133145
userObjects!!.forEach { user -> user!!.future!!.get() }
134146
}

0 commit comments

Comments
 (0)