-เดิมที memory ที่มีอยู่ใน Virtual Machine (VM) จะถูกหารไปใช้งานโดย number of region ซึ่งหนึ่งในนั้น คือ region ที่เป็น PermGen space (permanent generation space) ซึ่งเป็นพื้นที่ของ memory สำหรับโหลด class file เข้ามา
-สำหรับ size of memory region นั้น จะมีการกำหนดไว้อย่างคงที่โดยไม่มีการเปลี่ยนแปลงเมื่อ VM ทำงานอยู่ เราสามารถกำหนด size of region โดย -XX:MaxPermSize เช่น -XX:MaxPermSize = 256m หมายความว่า เรากำหนด size of memory region สูงสุดที่ 256 MB โดยหากเราไม่มีการกำหนด โดยพื้นฐานแล้วทางจะมีการกำหนดไว้ที่ 64 MB
วิธีการที่ garbage collector จัดการ... คือ ต้องเก็บ classes ใหม่ที่กำลังโหลดเข้ามาใน memory เป็นเหตุทำให้ VM นั้นเกิดการขาดแคลน space ใน memory region จึงต้องมี JAVA heap ไว้เพื่อช่วยจัดสรร memory ให้เพียงพอต่อ size of Object ที่อาศัยอยู่บน process heap ปัญหาที่เกิดตามมา ก็คือ... เกิด Object นั้นออกจาก process และคืน memory สู่ระบบ
-เนื่องจากว่า JAVA application จะทำงานตาม process เดี่ยวๆ ของแต่ละ process ที่ทำงานอยู่ โดยจะไม่มีการแชร์ memory ร่วมกันระหว่าง process ซึ่งแต่ละ process จะถูกจัดสรร memory ให้แต่ละ process เองโดย JVM ที่เรียกว่า process heap
เพราะฉะนั้น... การตั้งค่าพารามิเตอร์ –Xmx นั้นไม่ได้ช่วยอะไรมาก โดยพารามิเตอร์ดังกล่าว เป็นเพียงการกำหนด size of total heap เท่านั้น และไม่ได้ส่งผลกระทบอะไรต่อ size of PermGen region เลย
หลักๆ คือ ... -PermSize ไม่เพียงพอต่อการโหลด class file มาเก็บไว้ใน memory PermGen space
สิ่งที่ต้องทำ คือ ...
-กำหนดค่า PermGen space และ heap size ให้เพียงพอต่อความต้องการใช้งาน โดยทั่วไปเราจะกำหนด Environment Variables จาก JAVA_OPTS ซึ่งเป็น variable name ไว้กำหนดค่าต่างๆ ดังนี้
-ขั้นที่ 1 : generation จะแบ่งตามช่วงเวลาที่ memory pool นั้นได้ถือครอง object ในช่วงเวลาแตกต่างกันออกไป โดย object ใหม่ที่ถูกเรียกเข้ามาใช้งานนั้นจะมีการจอง memory เพื่อใช้งานใน young generation region (บางครั้งอาจจะเรียกว่า new generation region) เมื่อไม่ได้ใช้งานจะถูกนำไปเก็บไว้ที่ memory old generation region
-ขั้นที่ 2 : หาก memory young generation region เต็มแล้ว garbage collector จะทำการเรียกคืนหน่วยจำส่วนหนึ่ง ที่ไม่ได้มีการใช้งานแล้ว จาก old generation region แบ่งไปให้กับ young generation region
เดิมทีนั้น จะมีการแบ่ง generation ของ total heap size ต่อมาได้มีการแบ่ง old generation ออกมาเป็น tenured generation หลังจากที่ generational memory system นั้นได้ทำการหาร heap เข้าไป ใน sized partitions ที่ถูกแบ่งไว้อย่างระมัดระวังจะถูกเรียกว่า generation
–Xmn จะกำหนด size of the heap ที่ถูกจัดสรรสำหรับ Eden generation of the heap เพราะเริ่มแรก object ที่มีการใช้งานจะจอง memory เบื้องต้นบน Eden ก่อนที่จะถูกนำไปเก็บบน memory ทั้ง 2 spaces ระหว่าง survivor spaces จนกระทั่งมันไม่ได้ถูกเรียกใช้งาน และถูกนำไปเก็บไว้ยัง old generation region
โดยทั่วไปเราไม่ต้องการ Eden ที่ใหญ่เกินไป หรือใช้มากกว่าที่ garbage collector จะเรียกคืนสู่ระบบได้ จึงไม่จำเป็นต้องตั้งค่าให้กับพารามิเตอร์ -Xmn เพิ่มก็ได้
-นอกจากนี้ ก็มีการแนะนำต่ออีกว่า... ควรเลือก JDK ให้เหมาะสมกับ OS เพราะ OS 64 bit จะมี heap size default มากกว่า OS 32 bit เพื่อรองรับ size of object ที่ใหญ่ขึ้น
Keywork : JAVA Performance Tuning, Java Concurrency in Practice
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
และนี่ก็คือสรุปเนื้อหาทั้งหมดในงาน Google I/O 2016 โดยพี่เนย GDG Thailand ครับ...
Share Post
top.sk
Web Developer
Follow me on:
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
แหล่งข้อมูลอ้างอิง :
Google Developer Groups (GDGs) : Community สำหรับนักพัฒนาที่มีความสนใจในเทคโนโลยีของ Google เช่น Android, Chrome, Drive, Google Cloud platforms, Maps API, YouTube API http://www.gdg.in.th/ http://www.gdg.in.th/2016/io2016bkk
Share Post
top.sk
Web Developer
Follow me on:
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.
I can design web applications by using Java Server Faces (JSF), Primefaces, EJB3, SQL, DB2 (IBM) and designing report (Word, Excel and PDF) by using XML Script and Crystal Clear Report for the organization that can be easily and no problem for used and they can use the Web to manage the customer's organization effectively. I want to learn a new culture, technology and colleagues involved in the IT profession.