Latency in starting threads on Mac OS X
Michael Hall
mik3hall at gmail.com
Tue Apr 16 19:33:44 PDT 2013
On Apr 16, 2013, at 6:41 PM, Scott Palmer wrote:
> I doubt you are measuring what you think you are measuring. Maybe try the same while printing the GC details.
> -XX:+PrintGCDetails
GC does seem to make a difference.
Strange that would be platform specific.
Running the test as is I ended up with….
time = 6437, threads = 65103
Turning on the hotspot instrumentation seemed like it would have possible performance implications itself so instead I added periodic System.gc calls.
Which again, seemed to make a difference. I decided to eliminate most of the println's and just print the time result when threads topped 100k. Make showing a number of results more mailing list friendly.
Sort of interesting running this version with no additional gc now got…
java ThreadLeakMac2
time = 3592, join time 0, threads = 100795
a considerable improvement. Which almost makes you think all the String println's might of been dragging the original? So of strange they'd matter that much.
Other results with gc requested every 50 threads
Mac-User:~ mjh$ java ThreadLeakMac2 50
time = 3601, join time 0, threads = 100794
every 100 threads…
Mac-User:~ mjh$ java ThreadLeakMac2 100
time = 2278, join time 0, threads = 106937
every 150 threads…
Mac-User:~ mjh$ java ThreadLeakMac2 150
time = 3946, join time 0, threads = 100795
So there seems to be a significantly improved, optimal value, somewhere in the neighborhood of requested gc every 100 threads.
Undoubtedly, ymmv
My version…
public class ThreadLeakMac2 {
public static void main(String[] args) throws InterruptedException {
long threads = 0;
long max = 0;
boolean gc = false;
int GC_MOD = 0;
if (args.length > 0) {
gc = true;
GC_MOD = new Integer(args[0]).intValue();
}
while(true) {
long time = System.currentTimeMillis();
Thread thread = new Thread();
thread.start(); // should finish almost immediately
time = System.currentTimeMillis() - time;
long jtime = System.currentTimeMillis();
thread.join(); // short delay, hopefully
jtime = System.currentTimeMillis() - jtime;
threads++;
if (gc && threads % GC_MOD == 0) System.gc();
if (time > max) {
max = time;
if (threads > 100000) {
System.out.println("time = " + time + ", join time " + jtime +
", threads = " + threads);
break;
}
}
}
}
}
Michael Hall
trz nio.2 for OS X http://www195.pair.com/mik3hall/index.html#trz
HalfPipe Java 6/7 shell app http://www195.pair.com/mik3hall/index.html#halfpipe
AppConverter convert Apple jvm to openjdk apps http://www195.pair.com/mik3hall/index.html#appconverter
More information about the macosx-port-dev
mailing list