Hi Azeez, But, do we need to account for Thread.sleep time? Because, we are measuring the CPU usage. If the thread sleeps for a long time, it will get killed by the stuck thread detection valve.
Regards, AmilaM. On Mon, Jun 25, 2012 at 12:43 PM, Afkham Azeez <[email protected]> wrote: > Should we be using getThreadUserTime? Perhaps that will account for > Thread.sleep as well. > > > http://stackoverflow.com/questions/1001248/difference-between-thread-user-time-and-thread-cpu-time-in-java > > > On Tue, Jun 19, 2012 at 8:53 PM, Lasindu Vidana Pathiranage < > [email protected]> wrote: > >> I tried testing my code inside CarbonStuckThreadDetectionValve in >> org.wso2.carbon.tomcat.ext in carbon core inside invoke() method. What >> I did was when a thread passes through the valve to inside (Request) I >> measured the CPU time associated with it. When the thread passes again >> through the valve (after completing execution) I again measured the >> thread execution CPU time. >> >> Long key = Thread.currentThread().getId(); >> ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); >> System.out.println("Thread ID is : "+ key); >> System.out.println("Thread Execution CPU time is : >> "+threadBean.getThreadCpuTime(key)/ 1000000 + "ms"); >> System.out.println("Tenant Domain : "+ >> Utils.getTenantDomain(request)); >> System.out.println("Request URI : "+ request.getRequestURI()); >> >> System.out.println("-----------------------------------------------"); >> >> getNext().invoke(request, response); // previous code to >> invoke next valve inside invoke() method >> >> Long key2 = Thread.currentThread().getId(); >> System.out.println("Thread ID is(1) : "+ key2); >> System.out.println("Thread Execution CPU time is(1) : >> "+threadBean.getThreadCpuTime(key2)/ 1000000 + "ms"); >> System.out.println("Tenant Domain(1) : "+ >> Utils.getTenantDomain(request)); >> System.out.println("Request URI(1) : "+ >> request.getRequestURI()); >> System.out.println("================================"); >> >> >> Output when I tried with a Sample Web Service(with larger calculation >> inside a loop) in Application Server >> >> Thread ID is : 133 >> Thread Execution CPU time is : 20ms >> Tenant Domain : lasinduc.com >> Request URI : /carbon/admin/jsp/WSRequestXSSproxy_ajaxprocessor.jsp >> ----------------------------------------------- >> Thread ID is : 160 >> Thread Execution CPU time is : 0ms >> Tenant Domain : lasinduc.com >> Request URI : /services/t/ >> lasinduc.com/SimpleService.SimpleServiceHttpSoap12Endpoint/ >> ----------------------------------------------- >> Thread ID is(1) : 160 >> Thread Execution CPU time is(1) : 1860ms <--- Can be used as the >> CPU time of the particular request of the tenant >> Tenant Domain(1) : lasinduc.com >> Request URI(1) : >> /services/t/lasinduc.com/SimpleService.SimpleServiceHttpSoap12Endpoint/ >> ================================ >> Thread ID is(1) : 133 >> Thread Execution CPU time is(1) : 30ms >> Tenant Domain(1) : lasinduc.com >> Request URI(1) : /carbon/admin/jsp/WSRequestXSSproxy_ajaxprocessor.jsp >> ================================= >> >> Basically what I did was measuring the CPU time of a thread twice >> through a valve. (Before & after hitting axis2). This worked fairly >> well with the tests I did with AS and can be used to measure the CPU >> time per tenant in SLive. >> >> I tried this with sample web applications in the AS as well and worked >> fine and gave fairly measurable amount of time. What I can is to >> filter-in the necessary threads and measure CPU time per thread for a >> particular tenant. (with request URL : /t/lasinduc.com) >> >> What I can do next is to publish this CPU usage statistics per tenant >> to BAM and get the summation of CPU time at the end of the month or at >> any given point of time. >> >> Is there any other way where I could try this out or am I going in the >> right direction? >> >> >> >> Lasindu Charith >> Intern WSO2 Inc. >> Mobile : 94714427192 >> _______________________________________________ >> Dev mailing list >> [email protected] >> http://wso2.org/cgi-bin/mailman/listinfo/dev >> > > > > -- > *Afkham Azeez* > Director of Architecture; WSO2, Inc.; http://wso2.com > Member; Apache Software Foundation; http://www.apache.org/ > * <http://www.apache.org/>** > email: **[email protected]* <[email protected]>* cell: +94 77 3320919 > blog: **http://blog.afkham.org* <http://blog.afkham.org>* > twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez> > * > linked-in: **http://lk.linkedin.com/in/afkhamazeez* > * > * > *Lean . Enterprise . Middleware* > > > _______________________________________________ > Dev mailing list > [email protected] > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- *Amila Maharachchi* Technical Lead Member, Management Committee - Cloud & Platform TG WSO2, Inc.; http://wso2.com Blog: http://maharachchi.blogspot.com Mobile: +94719371446
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
