java - How to profile thread lifecycle performance -


in context of building http web server...we understand theoretically, creating , destroying threads per request relatively costly , doesn't scale well. common knowledge (or hope is). thread pools solution here...but kind of want understand things @ lower level accept theory true.

sure, can run black-box tests using jmeter see how application might perform under load, if want observe why happens? can profiler tool tell me how , why thread allocation per request costly?

thanks!

if wanted measure can this.

when wisdom divined long time ago when thread creation more expensive. e.g. on linux, each thread new process.

also "expensive" means different things different applications. if every request 1 system takes long time, adding milli-second won't make difference. if every request takes few milliseconds, adding milli-second start thread pretty bad.

import java.util.arraylist; import java.util.list;  public class threadrestartermain {     public static void main(string... ignored) throws interruptedexception {         long start = system.currenttimemillis();         // time how long takes start few threads , stop them again.         int threads = 2000;         list<thread> threadlist = new arraylist<>();         while (threadlist.size() < threads) {             thread e = new thread(new runnable() {                 @override                 public void run() {                     thread.yield();                 }             });             e.start();             threadlist.add(e);         }         (thread thread : threadlist) {             thread.join();         }         long time = system.currenttimemillis() - start;         system.out.printf("took %.3f ms on average start/stop thread%n", (double) time / threads);     } } 

this prints like

took 0.055 ms on average start/stop thread 

only know if large number.

note: if have thread local resources, can make timing longer. again depends on doing.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -