On Wed, Jun 20, 2012 at 2:27 PM, Selvaratnam Uthaiyashankar <
[email protected]> wrote:

>
>
> 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?
>>
>
>
> Hi Lasindu,
>
> I don't see any issue with your approach. You are in correct direction.
>
> Can you try this with various services? One with sleep (say 10 sec), one
> with busy loop (say 1million iterations + doing some mathematical
> calculation per each iteration.).
>

AFAIR Thread.sleep() times are not included in the CPU time which is
returned from this ThreadMXBean. Lasindu, please check this and confirm.

>
> Also, we might have to try above method in various servers, such as ESB,
> BPS and see the behavior.
>

+1 AFAIK Lasindu was testing this with AS. Better to test with other
servers as well.

Regards,
AmilaM.

>
> Shankar
>
>
>>
>>
>>
>> Lasindu Charith
>> Intern WSO2 Inc.
>> Mobile : 94714427192
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>
>
>
> --
> S.Uthaiyashankar
> Senior Software Architect
> Chair, Management Committee – Cloud Technologies
> WSO2 Inc.
> http://wso2.com/ - "lean . enterprise . middleware"
>
> Phone: +94 714897591
>
> _______________________________________________
> 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

Reply via email to