Hi Yavdhesh, all, Thanks for writing this up, and thanks to olka and milad-fa for the work on #6685 and #6506, and to milamberspace for the review of #6855.
I would like JMeter to support virtual threads, but only as a solid feature, not as a set of workarounds that each fix one symptom. JMeter is a measurement tool, so a change in how user threads run can change the numbers users report. Above all, I want to avoid regressions there. Before we decide how to add virtual threads, I think we need to know whether they solve the problem users have. Below I split the work into three groups: what is worth doing regardless of the result, the measurement that gives the result, and what we need only if the result is positive. Answers to your five questions are at the end. The open question The problem users describe is that one load generator cannot run enough users. None of the three PRs shows that virtual threads raise that limit. The benchmarks show fewer OS threads, which is true by construction. In #6855 the RSS drops by only 11% at 2000 users. I expect the drop is small because the JVM reserves address space for a platform thread stack but commits only the pages the thread uses. I also expect per-user memory to be dominated by the heap: the cloned test plan tree, JMeterVariables, and per-thread caches such as the HttpClient instances in HTTPHC4Impl and the SSL contexts. Virtual threads do not reduce any of that. There is a second question about accuracy. Virtual threads are not time-sliced. When a JSR223 post-processor or an extractor keeps a carrier thread busy, other users whose responses have already arrived wait to be scheduled, and that wait is added to their elapsed time. With platform threads the OS time-slices, so such a delay is spread across users; a virtual thread keeps its carrier until it blocks. milamberspace raised the same point in the #6855 review. A. Useful regardless of the result; can start now A1. Fix the monitors that user threads hold during blocking I/O. Even with platform threads, they make users wait for each other: - FileServer.readLine and getParsedLine (CSV Data Set): one monitor for the whole JVM, with disk reads under it. - SaveService.saveSampleResult: static synchronized, used for XML result files. - StatisticalSampleSender.sampleOccurred (mode=Statistical, distributed testing only): sends an RMI batch while holding the sampleStore monitor. A2. Report when the load generator itself is overloaded. A small probe (a thread that sleeps for a fixed interval and records how late it wakes up) shows CPU or GC saturation on the generator. Saturation distorts response times with platform threads too. The probe would report to the log or the Summariser output, with a warning above a threshold. With virtual threads, a second probe running as a virtual thread shows the delay in the virtual thread scheduler. A3. Reduce per-user memory, guided by B1, which needs no virtual thread code. If the cloned tree or the per-thread caches dominate, shrinking them raises the number of users per generator in either thread mode. B. The measurement that decides whether we need C #6855 can serve as an experimental build for this, without merging it. Use a realistic HTTP plan (HTTP sampler, Cookie and Header Manager, an extractor, an assertion) rather than a sampler that only sleeps, with both HttpClient4 and HttpClient5: B1. Where per-user memory goes: a heap histogram and Native Memory Tracking at a few thousand users, with platform threads. This tells us whether thread stacks are a significant part of per-user memory. B2. Capacity: the number of users a generator handles before its CPU, GC, or response times degrade, in both modes. B3. Accuracy: the difference between JMeter's elapsed time and the time the server reports for the same requests, at p50, p90, and p99, in both modes, including a plan with a CPU-heavy post-processor. If B1 shows that stacks are a small part of per-user memory, and B2 shows no capacity gain, I would stop at A. If virtual threads raise capacity without hurting B3, we continue with C. If capacity improves but accuracy suffers, we discuss it on the list before C. C. Needed only for virtual threads, after B C1. An extension point with no behavior change: a protected method on AbstractThreadGroup that creates the Thread for a JMeterThread. ThreadGroup, the setUp and tearDown thread groups, and OpenModelThreadGroup all go through it. OpenModelThreadGroup uses Executors.newCachedThreadPool() today, so it would silently ignore a property that only ThreadGroup reads. Thread groups in jmeter-plugins create their own threads too: Ultimate and Stepping Thread Group through AbstractSimpleThreadGroup, Concurrency and Arrivals Thread Group through AbstractThreadStarter. The plugin authors could move to the same method. C2. Diagnostics. ThreadDumper uses ThreadMXBean.dumpAllThreads, and JOrphanUtils.displayThreads uses Thread.getAllStackTraces. Neither lists virtual threads, so the ThreadDump UDP command, the GUI "What" action, and the exit check (jmeter.exit.check.pause) would stop showing user threads. HotSpotDiagnosticMXBean.dumpThreads (Java 21 and later) includes them; it writes to a file, so the GUI action would need a temporary file. Until then, jcmd <pid> Thread.dump_to_file is the workaround to document. C3. The opt-in switch, based on #6855 and rebased onto C1. Default off. I suggest enabling virtual threads only on Java 24 or later, where JEP 491 removed pinning for synchronized blocks. On Java 21 through 23, JMeter would log a warning and stay on platform threads. Converting JMeter's own locks would not cover third-party code that runs in user threads (JDBC drivers, script engines, client libraries), so on Java 21 pinning would remain either way. Java 25 is an LTS release, so this does not require an unusual JVM. The thread mode should appear in the log at test start, so results from the two modes are not mixed up. C4. A CI job that runs the existing batch tests with the switch on, on Java 25. Answers to your questions 1. Opt-in on the existing ThreadGroup as the base: yes, if B shows a benefit, built on the extension point from C1 so that it covers every thread group. 2. The ReentrantLock conversions from #6685: milamberspace suggested they could be worth reusing, but I would not bring them in as a block. The locks it converts in StandardJMeterEngine, ThreadGroup, AbstractThreadGroup, JMeterContextService, and TestCompiler update in-memory state and never block while held, so they do not pin a carrier thread in a way that matters. The monitors in A1 are the ones that block users, and they are worth fixing on their own merits. 3. A per-group element: later, if users ask for it. With C1 in place, a per-group setting is a small change, and it does not need a separate copy of the thread group lifecycle as in #6506. 4. The benchmark bar: B above. That is what milamberspace described (several thousand users over HTTP with HttpClient4 and HttpClient5, p90 and p99, generator CPU), plus the server-side reference for accuracy and the memory breakdown. 5. JEP 491: yes, it changes the sequencing. For that reason I suggest Java 24 or later for the switch, and dropping the bulk conversions. Anyone can pick up A1 and A2 now. B is the step that most needs a volunteer, and whoever wants virtual threads in JMeter is in the best position to run it with #6855 as it is. Thanks, Vladimir
