In this article, we will examine the following topics:
- What string table is
- How to find the number of interned strings in your applications
- The tradeoff between memory footprint and lookup cost
String Table
In Java, string interning[1] is a method of storing only one copy of each distinct string value, which must be immutable. Interning strings makes some string processing tasks more time- or space-efficient at the cost of requiring more time when the string is created or interned. The distinct values are stored in a string intern pool, which is the string table in HotSpot.
The size of the string table (i.e., a chained hash table) is configurable in JDK 7. When the overflow chains become long, performance can degrade. The current default size of string table is 1009 (or 1009 buckets), which is too small for applications that stress the string table. Note that the string table itself is allocated in native memory but the strings are java objects.
Increasing the size improves performance (i..e, reducing look-up cost) but increases the StringTable size by 16 bytes on 64-bit systems, 8 bytes on 32-bit systems for every additional entry. For example, changing the default size to 60013 increases the String Table size by 460K on 32 bit systems.
Finding Number of Interned Strings in the Applications
In HotSpot, it provides a product level option named PrintStringTableStatistics which can be used to print hash table statistics[4]. For example, using one of our applications (hereafter will be referred as JavaApp), it prints out the following information:
StringTable statistics:
Number of buckets : 60013
Average bucket size : 5
Variance of bucket size : 5
Std. dev. of bucket size: 2
Maximum bucket size : 17
You can find the above output from your manged server's log file in the WebLogic domain. Note that we have set the following option:
In JDK, there is also a tool named jmap which can be used to find out number of interned strings in your application. For example, we have found the following information using:
$ jdk-hs/bin/jmap -heap 18974
Attaching to process ID 18974, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.0-b43
using thread-local object allocation.
Parallel GC with 18 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 2147483648 (2048.0MB)
NewSize = 1310720 (1.25MB)
MaxNewSize = 17592186044415 MB
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 402653184 (384.0MB)
MaxPermSize = 402653184 (384.0MB)
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
<deleted for brevity>
Based on curiosity, we have tried to set the string table size to be 277331 (a prime number) to see how JavaApp performs. Here are our findings:
However, the memory footprint has increased:
Finally, here is the hash table statistics based on the new size (i.e., 277331):
StringTable statistics:
Number of buckets : 277331
Average bucket size : 1
Variance of bucket size : 1
Std. dev. of bucket size: 1
Maximum bucket size : 8
The conclusion is that increasing string table size from 60013 to 277331 helps JavaApp's performance a little bit at the expense of larger memory footprint. In this case, the benefit is minimal, keeping string table size to be 60013 is good enough.
Number of buckets : 60013
Average bucket size : 5
Variance of bucket size : 5
Std. dev. of bucket size: 2
Maximum bucket size : 17
You can find the above output from your manged server's log file in the WebLogic domain. Note that we have set the following option:
- -XX:StringTableSize=60013
In JDK, there is also a tool named jmap which can be used to find out number of interned strings in your application. For example, we have found the following information using:
$ jdk-hs/bin/jmap -heap 18974
Attaching to process ID 18974, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.0-b43
using thread-local object allocation.
Parallel GC with 18 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 2147483648 (2048.0MB)
NewSize = 1310720 (1.25MB)
MaxNewSize = 17592186044415 MB
OldSize = 5439488 (5.1875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 402653184 (384.0MB)
MaxPermSize = 402653184 (384.0MB)
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
<deleted for brevity>
270145 interned Strings occupying 40429904 bytes.
Therefore, we know there are around 260K interned Strings in the table.
Tradeoff Between Memory Footprint and Lookup Cost
Based on curiosity, we have tried to set the string table size to be 277331 (a prime number) to see how JavaApp performs. Here are our findings:
- Average Response Time: +0.75%
- 90% Response Time: +0.56%
However, the memory footprint has increased:
- Total Memory Footprint: -1.03%
Finally, here is the hash table statistics based on the new size (i.e., 277331):
StringTable statistics:
Number of buckets : 277331
Average bucket size : 1
Variance of bucket size : 1
Std. dev. of bucket size: 1
Maximum bucket size : 8
References
- String Interning (Wikipedia)
- JDK 6962930 : make the string table size configurable
- JDK 8009928: Increase default value for StringTableSize
- Java GC tuning for strings
- All other performance tuning articles on XML and More
- G1 GC Glossary of Terms
I really liked your article and the photo is super. Thanks you. If you need to write a good article you need to use the essay writer online.
ReplyDeleteVery positive photos. Thank you for the article.Who can do my homework essay?
ReplyDeleteI love your blogs because your content keeps on finding new bugs. But in this case, I think the string would be collapse, because constant stress won’t allow it. Buy dissertation online
ReplyDeleteNino Nurmadi, S.Kom
ReplyDeleteninonurmadi.com
ninonurmadi.com
ninonurmadi.com
Nino Nurmadi, S.Kom
Nino Nurmadi, S.Kom
Nino Nurmadi, S.Kom
Nino Nurmadi , S.Kom
Nino Nurmadi, S.Kom
I’m really loved this blog, thanks for sharing such an amazing blog. Visit OGEN Infosystem for creative Website Designing and SEO Services in Delhi, India.
ReplyDeleteSEO Service in Delhi
Nice one! thank you so much! Thank you for sharing this post. Your blog posts are more interesting and impressive.
ReplyDeleteArmy Public School Beas
Army Public School Basistha
Army Public School Barrackpore
Army Public School Bagrakote
Army Public School Babina
Army Public School Amritsar
Army Public School Akhnoor
Army Public School Ahmednagar
Army Public School Ahmedabad
Army Public School Trivandrum
Nice one! thank you so much! Thank you for sharing this post. Your blog posts are more interesting and impressive.
ReplyDeleteKendriya Vidyalaya IIT Powai
Kendriya Vidyalaya INS Hamla Powai
Kendriya Vidyalaya No 2 Colaba
Kendriya Vidyalaya No 3 Colaba
Kendriya Vidyalaya Solapur
Kendriya Vidyalaya No 1 Ahmednagar
Kendriya Vidyalaya No 2 Ahmednagar
Kendriya Vidyalaya No 3 Ahmednagar
Kendriya Vidyalaya Bhandara
Kendriya Vidyalaya WCL Chandrapur
I have read it completely and got really impressed. Love to read more about similar types of articles. Thanks a lot!!
ReplyDeletedissertation writing services uk
Hi there
ReplyDeleteNice post and blog, keep sharing the best content, hope to read more interesting articles like this one,
take care and regards
Your follower
Salvatore from Golf Club
Howdy! I could have sworn I've visited your blog before but after looking at some of the articles I realized it's new to me. Anyways, I'm certainly happy I found it and I'll be book-marking it and checking back often! Check out our Hosting Discount Coupons
ReplyDeleteNice post.
ReplyDeleteScholarship Practice Test
Kotlin was set in 2010 by JetBrains to tackle engineer difficulties the organization confronted. In 2012, this statically-composed programming language, highlighting type interface, became open source. Kotlin is a universally useful programming language which was at first intended for the Java Virtual Machine (JVM) and Android. Today, it focuses on the JVM, Android, JavaScript and Local. Kotlin bases on interoperability, while it likewise has areas of strength for an on security, clearness, and tooling support. For some, Kotlin might seem to be a more smoothed out variant of Java, as a matter of fact, Kotlin was roused by Java, however there are various contrasts. The fundamental contrast is that Kotlin is more compact and uses impressively less code>> hire kotlin developers
ReplyDeleteThis article provides a comprehensive overview of the DevOps incident management process and how to effectively respond to system failures. It outlines key steps, best practices, and tools to ensure a smooth and efficient incident response. The practical tips and real-life examples make it a valuable resource for DevOps professionals.
ReplyDeleteHello!
ReplyDeleteThat's a nice post and blog, thanks you for your work and keep sharing the best content youtube brasil take care!
Regards
Your follower,
Josh Alex