db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Dudziak <to...@first.fhg.de>
Subject Re: Vector use
Date Tue, 15 Jun 2004 10:30:52 GMT
Ilkka Priha wrote:

> Synchronization overhead is surprisingly low, at least with the newest 
> Java VMs, in non-concurrent situations, but can cause bottlenecks in 
> concurrent ones, which really slows down performance. On the other 
> hand, if concurrency is expected, collections can't be substituted 
> with non-synchronized classes without resolving the normal issues of 
> thread-safety.
>
> As this topic has come up in almost all of our Java projects, we've 
> made some simple benchmarks with ordered Integer objects to test 
> (only) synchronization of collections. All collections have been 
> constructed with enough space to hold the test objects (150% with 
> maps) to avoid reallocation and rehashing. GC is called just before 
> each test case.
>
> With integer based over-simplified hashcodes Hashtable and Vector 
> perform actually better than the corresponding HashMap and ArrayList 
> because their put, get and remove methods are somewhat simpler and 
> call less internal methods. Synchronization of HashMap with 
> Collections.syncronizedMap cause an overhead between 2-7 % depending 
> on the operation. Synchronization of ArrayList with 
> Collections.syncronizedList cause quite high relative overhead but 
> it's only about 10 ns per call. Other benchmarks have shown that in 
> more realistic hashing situations HashMap should perform better then 
> Hashtable but probably because of better rehashing than missing 
> synchronization.
>
> Sun JRE 1.4.2_004, Windows XP Pro, AMD Athlon XP 2400+, 1024 MB
> ---------------------------------------------------------------
> INFO [15/Jun/2004:08:03:20 +0000] Hashtable put 5000000 times:         
> 1324
> INFO [15/Jun/2004:08:03:20 +0000] Hashtable get 5000000 times:         
> 468
> INFO [15/Jun/2004:08:03:21 +0000] Hashtable remove 5000000 times:     452
> INFO [15/Jun/2004:08:03:27 +0000] HashMap put 5000000 times:         3849
> INFO [15/Jun/2004:08:03:29 +0000] HashMap get 5000000 times:         2508
> INFO [15/Jun/2004:08:03:33 +0000] HashMap remove 5000000 times:     3397
> INFO [15/Jun/2004:08:03:39 +0000] Synced HashMap put 5000000 
> times:     3942
> INFO [15/Jun/2004:08:03:42 +0000] Synced HashMap get 5000000 
> times:     2680
> INFO [15/Jun/2004:08:03:45 +0000] Synced HashMap remove 5000000 
> times:     3459
> INFO [15/Jun/2004:08:03:47 +0000] Vector add 5000000 times:         203
> INFO [15/Jun/2004:08:03:47 +0000] Vector get 5000000 times:         171
> INFO [15/Jun/2004:08:03:47 +0000] Vector remove 5000000 times:         
> 156
> INFO [15/Jun/2004:08:03:49 +0000] ArrayList add 5000000 times:         
> 172
> INFO [15/Jun/2004:08:03:49 +0000] ArrayList get 5000000 times:         
> 187
> INFO [15/Jun/2004:08:03:49 +0000] ArrayList remove 5000000 times:     171
> INFO [15/Jun/2004:08:03:50 +0000] Synced ArrayList add 5000000 
> times:     218
> INFO [15/Jun/2004:08:03:51 +0000] Synced ArrayList get 5000000 
> times:     234
> INFO [15/Jun/2004:08:03:51 +0000] Synced ArrayList remove 5000000 
> times: 530
>
> With multi-processor hardware the synchronization takes more time 
> because the underlying mechanism is much more complicated. We've run 
> benchmarks only in a two processor machine. Even there Hashtable 
> performs better than HashMap, but Vector is now clearly slower than 
> ArrayList (but still faster than synchronized ArrayList).
>
> Windows 2000 Server, 2 x Intel PIII 1266 MHz, 512 MB
> ---------------------------------------------------------------------
> INFO [15/Jun/2004:08:15:12 +0000] Hashtable put 5000000 times: 3172
> INFO [15/Jun/2004:08:15:13 +0000] Hashtable get 5000000 times: 953
> INFO [15/Jun/2004:08:15:14 +0000] Hashtable remove 5000000 times: 969
> INFO [15/Jun/2004:08:15:22 +0000] HashMap put 5000000 times: 5813
> INFO [15/Jun/2004:08:15:25 +0000] HashMap get 5000000 times: 2437
> INFO [15/Jun/2004:08:15:28 +0000] HashMap remove 5000000 times: 3594
> INFO [15/Jun/2004:08:15:37 +0000] Synced HashMap put 5000000 times: 6485
> INFO [15/Jun/2004:08:15:40 +0000] Synced HashMap get 5000000 times: 2922
> INFO [15/Jun/2004:08:15:44 +0000] Synced HashMap remove 5000000 times: 
> 4234
> INFO [15/Jun/2004:08:15:47 +0000] Vector add 5000000 times: 688
> INFO [15/Jun/2004:08:15:47 +0000] Vector get 5000000 times: 593
> INFO [15/Jun/2004:08:15:48 +0000] Vector remove 5000000 times: 579
> INFO [15/Jun/2004:08:15:51 +0000] ArrayList add 5000000 times: 313
> INFO [15/Jun/2004:08:15:51 +0000] ArrayList get 5000000 times: 296
> INFO [15/Jun/2004:08:15:51 +0000] ArrayList remove 5000000 times: 344
> INFO [15/Jun/2004:08:15:54 +0000] Synced ArrayList add 5000000 times: 735
> INFO [15/Jun/2004:08:15:54 +0000] Synced ArrayList get 5000000 times: 703
> INFO [15/Jun/2004:08:15:55 +0000] Synced ArrayList remove 5000000 
> times: 719
>
> -- Ilkka

Pretty interesting stuff. I guess, some profiling is in order after the 
1.0 ;-)

Tom


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


Mime
View raw message