Skip to main content

JVM Performance Optimization

How to set JVM parameters

The performance of the JVM depends on how well it is configured to match the functionality of the application. Although memory is automatically managed using garbage collection and memory reallocation processes, you have control over their frequency. In general, the more memory you have available for your application, the less memory management processes are required, which pause your application.
If garbage collections are occurring more frequently than you would want, you can start the JVM with more maximum heap size. The longer it takes for a generation of the heap to fill up, the fewer garbage collections occur. To configure the maximum heap size, use the -Xmx option when you start the JVM. By default, the maximum heap size is set to either 1/4th of the physical memory available to the OS, or to 1 GB (whichever is the smallest).
If the problem is with memory reallocation, you can set the initial heap size to be the same as the maximum. This means that the JVM will never need to allocate more memory to the heap. However, you will also lose the adaptive memory optimization gained from dynamic heap sizing. The heap will be of fixed size from the moment you start your application. To configure the initial heap size, use the -Xms option when you start the JVM. By default, the initial heap size is set to either 1/64th of the physical memory available to the OS, or to some reasonable minimum that is different for different platforms (whichever is the largest).
If you know which garbage collections (minor or major) are causing performance degradation, you can set the ratio between the young and old generations without changing the overall heap size. For applications that create a lot of short-lived objects, increase the size of the young generation (this will leave less memory for the old generation). For applications that operate with a lot of longer surviving objects, increase the size of the old generation (by setting less memory for the young generation). The following ways can be used to control the sizes of the young and old generations.
  • Specify the ratio between the young and old generation using the -XX:NewRatio option when you start the JVM. For example, to make the old generation five times larger than the young generation, specify -XX:NewRatio=5. By default, the ratio is set to 2 (the old generation occupies ⅔ of the heap, and the young generation occupies ⅓).
  • Specify the initial and maximum size of the young generation using the -Xmn option when you start the JVM. The old generation size will be set to whatever memory remains on the heap.
  • Specify the initial and maximum size of the young generation separately, using the -XX:NewSize and -XX:MaxNewSize options when you start the JVM. The old generation size will be set to whatever memory remains on the heap.
Most applications (especially servers) require concurrent execution, handling a number of tasks. Some of these tasks are more important at a given moment, while others are background tasks that can be executed whenever the CPU is not busy doing anything else. Tasks are executed in different threads. For example, a server may have a low-priority thread that calculates statistics based on some data and starts a higher-priority thread to handle incoming data, and another higher-priority thread to serve a request for some of the data that was calculated. There can be many sources of data, and many clients requesting data from the server. Each request will briefly stop the execution of the background calculation thread to serve the request. So you have to monitor the number of threads that are running and make sure there is enough CPU time for the thread that is making the necessary calculations.
Each thread has a stack that holds the method calls, return addresses, and so on. Some memory is allocated for the stack, and if there are too many threads, this can lead to an OutOfMemory error. Even if you have enough heap memory allocated for objects, your application may be unable to start a new thread. In this case, consider limiting the maximum size of the stack in threads. To configure the thread stack size, use the -Xss option when you start the JVM. By default, the thread stack size is set to 320 KB or 1024 KB, depending on the platform.
Reference:
https://anturis.com/blog/java-virtual-machine-the-essential-guide/

Comments

Popular posts from this blog

湾区好吃的中餐馆

一个伪吃货在湾区的checklist 来源: 徐聪的日志 海鲜: Boiling Crab (San Jose), Joe's Crab Shack (San Francisco) , Tomi Sushi & Seafood Buffet(San Jose), Tatami Sushi & Seafood Buffet(Cupertino) 番外:Pier 39  的大螃蟹  (San Francisco) Boiling Crab的螃蟹从来都是酒香不怕巷子深,关键在于它家的酱绝对不会让人想起它 是一家西餐馆。它家的龙虾也是一绝,当然一旦点了龙虾还打算吃饱的话人均基本在40 刀以上。它家在San Jose有两家分店,如果想避免排长队的话推荐周末中午11点50点以 前(12点开门)去101高速边上那家,屡试不爽。 Joe's Crab Shack是一家全美连锁的海鲜餐馆,一锅端 (Steampot) 的吃法很有特色。 Tomi Sushi & Seafood Bufferz中文名叫涛味,排在Tatami之前的原因是它家的口味比 较偏中餐,龙虾膏蟹做的不错(不是每天都有)。最近中午去过一次,东西很少,不推 荐中午去(虽然价格便宜一些)。 Tatami跟南加著名的Todai都是差不多的日式海鲜自助,生鱼片比较新鲜,不过没有 Todai每小时限量的烤龙虾尾。 渔人码头的螃蟹主要的砝码是价格,但跟Boling Crab一比也不见得能便宜多少。有一 家摊位上面写着“我们通晓国、粤、英语”,每次都会去。 川菜: 御食园(San Francisco),金饭碗(Berkeley), 红翻天(Foster City), 吃香喝 辣(Newark), 老赵川菜(Mountain View), 鹿鸣春(Berkeley), 福恩园( Menlo Park),麻辣诱惑(Fremont), 巴山蜀水(Milpitas) , 福恩园(San  Mateo), 大四川(Palo Alto), 麻辣诱惑(San Jose), 山城私房菜(Milpitas ),麻辣帝国(San Mateo) 川菜的菜品基本都是那几样,就不单独推荐了。 排名第一的Z&Y我觉得就不用...

北美 加州 草坪维护 草黄了怎么办

当今中国有句顺口溜, 叫做:穷的时候种稻, 富的时候种草。我虽然 不富,但也种了几年的 草。我对种草其实懂得 不多,虽自学不辍,但 终未成才。不过到底种 了几年的草,心得和体 会总是有的。现在把我 的心得体会写出来,希 望对房前屋后有块小草 坪的朋友们,不管是穷 还是富,都有些帮助。 草地上的草,都属于禾 本科(Grass Family),与竹 子、水稻、小麦、甘蔗 和狗尾巴花是同一个科 的植物。从个体的数量 和分布的范围来讲,禾 本科植物应该是植物界 最大的科了。草本的禾 本科植物通常有两种生 长的形态,一种叫蓬草 (bunch grass),一种叫 坪草(sod grass)。用来做 草坪的草,当然都是坪 草 。坪草的物种和品种很 多,不同地区不同气候 条件种的草不一样,但 也有一些共性。一般来 说,当地商店里买的草 籽(grass seeds)和草皮( sod),都是比较适 合当地的自然条件的。 一.维护和保养草坪必 做的四件事情 1.割草。定期割草, 不仅能使草坪美观,而 且也可防止或减缓坪草 从营养生长到生殖生长 的过渡。营养生长就是 长叶子,生殖生长就是 开花结籽。很多人都知 道,春天的时候有一段 时间不割草,草就开花 结籽了。大家也见过, 边边角角割不到草的地 方,那里的草就会开花 结籽。 2.浇水。对北美大部 分地区来说,春秋天时 可视情况少浇水甚至不 浇水。草地最需要浇水 的时候是夏天,因为夏 天最热最干,水分蒸发 快。至于浇水要多频繁 ,那就看你想草地是保 绿,还是保命。如果想 保绿,那草地每星期得 有一英寸的水量。除非 有自动浇水系统,浇水 是很费时间的,也费钱 。我只想我的草地保命 ,所以我的草地夏天基 本不浇水,只在特别容 易干死的草地或在特别 干旱的年份浇点水。所 以到8-9月份的时候 ,我的草地就黄黄的了 ,有些难看。不过,一 场秋雨来,草地依旧绿 。 3.施肥。草地的肥料 应以氮素为主,钾素得 有一点,但磷的含量可 以很低。我用的最多的 草坪肥料是30-0- 4。现在有一种运动, 推崇不含磷素的草地肥 料,因为磷素施用过多 ,会引起水体(如湖泊 ,池塘)的富营养化。 施肥的话,还是得买个 撒肥机(spread er/broadca ster),手持的或 手推的型号都行,当地 商店都有卖的。没有撒 肥机,肥料会撒得很不 均匀。 4.杂草...

美国买房 房屋类型简介

关于房屋分类的简单介绍 前几天看到一个有关TH和CONDO差别的讨论。现根据本人的知识给大家介绍一下, 也许 有错或者不全, 希望大家补充。如果版主认为此帖对大众有益, 请暂时置顶。 民用房屋一般分三类: 1. SFR (Single Family Residential---独立屋):其特征是有土地,有yard,大部 分没有CC & R和 HOA,个别lot小的有CC & R,甚至有HOA。 进一步划分: a) SFR Detached: 这个就是最典型的别墅房子,其特征是整个建筑前后,左右, 上下 都完全与邻居独立。Zoning code 是 R1。 如果只有一边有side yard, 另一边的墙就是邻居的boundary, 好像当作fence 一样  (所以这一边的墙上不能开窗)。这类房子的zoning code 是 APD, 或者叫zero lot。 每个城市对R1的min lot size有不同的要求, 有的6000尺(譬如说San Jose 或其他大 部分的湾区城市), 有的8000尺(譬如说Saratoga),如果lot小到一定程度, 譬如 说4500 尺或以下, 就zone为PUD (Plan Unit Development)。 b) SFR Attached: 这个就是通常讲的双拼房 (duet home)。 其特征是二家share一 堵墙 (有的时候二家有各自的墙 , 但是连在一起)。与下面要讲的Duplex不同的是 : 二家有各自的门牌号码, 可以独立分开贷款和买卖, 往往没有 CC & R和 HOA, 但有deed restriction 来规定如何维护share wall。 2. Condominium:其特征是你总是和别家share something, 一定有CC & R和 HOA. 进一步划分: a)Town house (镇屋): 其特征是上下building都是归你居住, 往往有独立的门牌 号码。 有的TH legal 上有地(lot),有yard。 但是和SFR还是有很大的不同, 不能随便使 用,要完全遵守CC & R和 HOA的规定。甚至有些TH zone 为PUD的。 b)Condo (共渡公寓):其特征是往往有邻居住在你家的上面或下面,大部分情况下 门牌号码后面还要加一个U...