l*****b 发帖数: 82 | 1 am testing the servlet application using tomcat and customized multithreded
test clients. I try the following different scenarios - synchronize or not
the servlet method. In client side, I generate 200 concurrent requests to
this servlet. There are quite different CPU usage in this scenarios: non-
synchronized one use much more CPU (almost 100%) than synchronized (as usual
). Could anyone advise me what's happened there and why has that different?
e.g.
public TestServlet .....{
public void doGet | m******t 发帖数: 2416 | 2
multithreded
usual
Execution in handleRequest() is serialized with
the synchronized version, hence the low cpu utilization.
【在 l*****b 的大作中提到】 : am testing the servlet application using tomcat and customized multithreded : test clients. I try the following different scenarios - synchronize or not : the servlet method. In client side, I generate 200 concurrent requests to : this servlet. There are quite different CPU usage in this scenarios: non- : synchronized one use much more CPU (almost 100%) than synchronized (as usual : ). Could anyone advise me what's happened there and why has that different? : e.g. : public TestServlet .....{ : public void doGet
| l*****b 发帖数: 82 | 3 Hi, magicfat , thank you. Many suggest to take "synchronized" out. My
Servlet has no any instance or static variable. Could I assume the un-
synchronized method is still thread safe? And this high CPU usage is normal
case for un-synchronized method? | F****n 发帖数: 3271 | 4 Why you so care about high CPU usage? It means your requests are handled
concurrently and therefore faster. Servlet should not have state in most
cases, so there is really no need to make it thread safe. If you need to
access some stateful data, put them into some objects and make them thread
safe.
normal
【在 l*****b 的大作中提到】 : Hi, magicfat , thank you. Many suggest to take "synchronized" out. My : Servlet has no any instance or static variable. Could I assume the un- : synchronized method is still thread safe? And this high CPU usage is normal : case for un-synchronized method?
| l*****b 发帖数: 82 | 5 Hi, all, many thanks. Your advice is helpful indeed. BTW, I am a performance
zealot. | F****n 发帖数: 3271 | 6 But high CPU usage actually means it's faster (No waiting line!)
performance
【在 l*****b 的大作中提到】 : Hi, all, many thanks. Your advice is helpful indeed. BTW, I am a performance : zealot.
| m******t 发帖数: 2416 | 7
performance
Well, as Foxman said, high CPU utilization is
A Good Thing(tm). 8-)
(Not too high though, you want to keep the running
average under 50% or even lower)
【在 l*****b 的大作中提到】 : Hi, all, many thanks. Your advice is helpful indeed. BTW, I am a performance : zealot.
|
|