You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Konstantin Kolinko <kn...@gmail.com> on 2009/06/18 12:00:14 UTC

Re: svn commit: r785952 - in /tomcat/trunk/test/org/apache/catalina/valves: ./ Benchmarks.java

2009/6/18  <ma...@apache.org>:
> Author: markt
> Date: Thu Jun 18 08:32:29 2009
> New Revision: 785952
>
> URL: http://svn.apache.org/viewvc?rev=785952&view=rev
> Log:
> Add some micro-benchmarks that enable the differences between the Sync and ThreadLocal approach to be compared
>
> Added:
>    tomcat/trunk/test/org/apache/catalina/valves/
>    tomcat/trunk/test/org/apache/catalina/valves/Benchmarks.java
>
> (...)
> +        private ThreadLocal<SimpleDateFormat> yearFormatterLocal =
> +            new ThreadLocal<SimpleDateFormat>() {
> +            protected SimpleDateFormat initialValue() {
> +                return new SimpleDateFormat("yyyy");
> +            }
> +        };
> +        private ThreadLocal<SimpleDateFormat> timeFormatterLocal =
> +            new ThreadLocal<SimpleDateFormat>() {
> +            protected SimpleDateFormat initialValue() {
> +                return new SimpleDateFormat("hh:mm:ss");
> +            }
> +        };
> +

I wonder,
may be we can have a single ThreadLocal that holds some object
that stores all the formatters (maybe with lazy initialization),
instead of wrapping each one individually?

Will it make some difference?


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r785952 - in /tomcat/trunk/test/org/apache/catalina/valves: ./ Benchmarks.java

Posted by Xie Xiaodong <xx...@gmail.com>.
sorry, maybe I misunderstood your code, I'll recheck it.

2009/6/18 Xie Xiaodong <xx...@gmail.com>

> Mark, since each of your thread runs a TestThread which implements
> runnable, those thread do not access the field or method of other threads, I
> do not think the test is multi-threaded. You could use one or two
> your BenchmarkTest class, and let more than more thread access its method
> instead.
>
>
>
> 2009/6/18 Mark Thomas <ma...@apache.org>
>
> Konstantin Kolinko wrote:
>> > 2009/6/18  <ma...@apache.org>:
>> >> Author: markt
>> >> Date: Thu Jun 18 08:32:29 2009
>> >> New Revision: 785952
>> >>
>> >> URL: http://svn.apache.org/viewvc?rev=785952&view=rev
>> >> Log:
>> >> Add some micro-benchmarks that enable the differences between the Sync
>> and ThreadLocal approach to be compared
>> >>
>> >> Added:
>> >>    tomcat/trunk/test/org/apache/catalina/valves/
>> >>    tomcat/trunk/test/org/apache/catalina/valves/Benchmarks.java
>> >>
>> >> (...)
>> >> +        private ThreadLocal<SimpleDateFormat> yearFormatterLocal =
>> >> +            new ThreadLocal<SimpleDateFormat>() {
>> >> +            protected SimpleDateFormat initialValue() {
>> >> +                return new SimpleDateFormat("yyyy");
>> >> +            }
>> >> +        };
>> >> +        private ThreadLocal<SimpleDateFormat> timeFormatterLocal =
>> >> +            new ThreadLocal<SimpleDateFormat>() {
>> >> +            protected SimpleDateFormat initialValue() {
>> >> +                return new SimpleDateFormat("hh:mm:ss");
>> >> +            }
>> >> +        };
>> >> +
>> >
>> > I wonder,
>> > may be we can have a single ThreadLocal that holds some object
>> > that stores all the formatters (maybe with lazy initialization),
>> > instead of wrapping each one individually?
>> >
>> > Will it make some difference?
>>
>> Don't know. You could always add your own test to the benchmarks and find
>> out :)
>>
>> Mark
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: dev-help@tomcat.apache.org
>>
>>
>
>
> --
> Sincerely yours and Best Regards,
> Xie Xiaodong
>



-- 
Sincerely yours and Best Regards,
Xie Xiaodong

Re: svn commit: r785952 - in /tomcat/trunk/test/org/apache/catalina/valves: ./ Benchmarks.java

Posted by Xie Xiaodong <xx...@gmail.com>.
Mark, since each of your thread runs a TestThread which implements runnable,
those thread do not access the field or method of other threads, I do not
think the test is multi-threaded. You could use one or two
your BenchmarkTest class, and let more than more thread access its method
instead.



2009/6/18 Mark Thomas <ma...@apache.org>

> Konstantin Kolinko wrote:
> > 2009/6/18  <ma...@apache.org>:
> >> Author: markt
> >> Date: Thu Jun 18 08:32:29 2009
> >> New Revision: 785952
> >>
> >> URL: http://svn.apache.org/viewvc?rev=785952&view=rev
> >> Log:
> >> Add some micro-benchmarks that enable the differences between the Sync
> and ThreadLocal approach to be compared
> >>
> >> Added:
> >>    tomcat/trunk/test/org/apache/catalina/valves/
> >>    tomcat/trunk/test/org/apache/catalina/valves/Benchmarks.java
> >>
> >> (...)
> >> +        private ThreadLocal<SimpleDateFormat> yearFormatterLocal =
> >> +            new ThreadLocal<SimpleDateFormat>() {
> >> +            protected SimpleDateFormat initialValue() {
> >> +                return new SimpleDateFormat("yyyy");
> >> +            }
> >> +        };
> >> +        private ThreadLocal<SimpleDateFormat> timeFormatterLocal =
> >> +            new ThreadLocal<SimpleDateFormat>() {
> >> +            protected SimpleDateFormat initialValue() {
> >> +                return new SimpleDateFormat("hh:mm:ss");
> >> +            }
> >> +        };
> >> +
> >
> > I wonder,
> > may be we can have a single ThreadLocal that holds some object
> > that stores all the formatters (maybe with lazy initialization),
> > instead of wrapping each one individually?
> >
> > Will it make some difference?
>
> Don't know. You could always add your own test to the benchmarks and find
> out :)
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>


-- 
Sincerely yours and Best Regards,
Xie Xiaodong

Re: svn commit: r785952 - in /tomcat/trunk/test/org/apache/catalina/valves: ./ Benchmarks.java

Posted by Mark Thomas <ma...@apache.org>.
Konstantin Kolinko wrote:
> 2009/6/18  <ma...@apache.org>:
>> Author: markt
>> Date: Thu Jun 18 08:32:29 2009
>> New Revision: 785952
>>
>> URL: http://svn.apache.org/viewvc?rev=785952&view=rev
>> Log:
>> Add some micro-benchmarks that enable the differences between the Sync and ThreadLocal approach to be compared
>>
>> Added:
>>    tomcat/trunk/test/org/apache/catalina/valves/
>>    tomcat/trunk/test/org/apache/catalina/valves/Benchmarks.java
>>
>> (...)
>> +        private ThreadLocal<SimpleDateFormat> yearFormatterLocal =
>> +            new ThreadLocal<SimpleDateFormat>() {
>> +            protected SimpleDateFormat initialValue() {
>> +                return new SimpleDateFormat("yyyy");
>> +            }
>> +        };
>> +        private ThreadLocal<SimpleDateFormat> timeFormatterLocal =
>> +            new ThreadLocal<SimpleDateFormat>() {
>> +            protected SimpleDateFormat initialValue() {
>> +                return new SimpleDateFormat("hh:mm:ss");
>> +            }
>> +        };
>> +
> 
> I wonder,
> may be we can have a single ThreadLocal that holds some object
> that stores all the formatters (maybe with lazy initialization),
> instead of wrapping each one individually?
> 
> Will it make some difference?

Don't know. You could always add your own test to the benchmarks and find out :)

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org