ARTIFACTORY: Optimizing Artifactory JVM Settings: Best Practices

ARTIFACTORY: Optimizing Artifactory JVM Settings: Best Practices

AuthorFullName__c
Pranav Hegde
articleNumber
000006217
ft:sourceType
Salesforce
FirstPublishedDate
2024-10-28T13:18:04Z
lastModifiedDate
2024-10-29
VersionNumber
5
Optimizing the Java Virtual Machine (JVM) settings for JFrog Artifactory is crucial for ensuring high performance, reliability, and stability. Proper tuning can lead to improved response times, reduced latency, and better resource utilization.


Why Optimize JVM Settings?

Artifactory runs on the JVM, and its performance is directly influenced by how the JVM is configured. Incorrect settings can lead to memory issues, slow performance, and application crashes, especially under heavy load.



Best Practices for Optimizing Artifactory JVM Settings

1. Analyze Your Environment:

  • Understand Workload: Analyze the usage patterns, including the number of concurrent users, the size of artifacts, and the frequency of requests.
  • Monitor Performance: Use monitoring tools to track memory usage, CPU load, and response times.

 

2. Set Heap Size Appropriately:

  • Initial and Maximum Heap Size:
    • Use the -Xms and -Xmx flags to set the initial and maximum heap sizes.
    • A common practice is to set -Xms to 25% of the system's RAM and -Xmx to 50-75%, but this varies based on your environment. When increasing the JVM memory allocation, make sure you leave at least 30% of the total RAM to the OS and other services.
E.g: You should update the following value in the system.yaml file for the Artifactory microservice.
        shared:
         extraJavaOpts:” -Xms2g -Xmx8g”
  • For Access service, JFrog is implementing a significant architectural update to Artifactory to improve resource management and strengthen the infrastructure. From Artifactory version 7.90 Self-Hosted, Access service will now run on a dedicated Java Virtual Machine (JVM) with a dedicated Tomcat server, independent of the main Artifactory JVM. For more details, you can refer to the following link.
To set Java parameters to the Access JVM, access.extraJavaOpts configuration is already added to the Artifactory System YAML. 
The values in the example below are merely illustrative and should be modified according to the size and usage of the Artifactory instance:
       access:
         extraJavaOpts: "-XX:InitialRAMPercentage=10 
-XX:MaxRAMPercentage=30"

-XX:InitialRAMPercentage is used to compute the initial heap size of your Java application. If configuring -XX:InitialRAMPercentage=25 and the overall physical server (or container) memory is 1GB, then your Java application’s initial  heap size will be set to 250MB (i.e., 25% of 1GB)

-XX:MaxRAMPercentage is used to compute the maximum Java heap size for your Java application. If configuring -XX:MaxRAMPercentage=30 and the overall physical server (or container) memory is 1GB, then your Java application’s max heap size will be set to 300MB (i.e., 30% of 1GB).


E.g: Here’s how the system.yaml looks after adding JVM settings for both the Artifactory and Access microservices.
 shared:
   extraJavaOpts: “-Xms2g -Xmx8g”
 access:
    extraJavaOpts: "-XX:InitialRAMPercentage=10 -XX:MaxRAMPercentage=25"

3. Use Garbage Collection Options:
  • Choose the Right Garbage Collector:
    • The G1 Garbage Collector is often recommended for Artifactory due to its efficiency with large heaps and ability to minimize pause times.

E.g: 

  Shared:
    extraJavaOpts: “-Xms2g -Xmx8g -XX:+UseG1GC”

 

  • Tune Garbage Collection: 
    Set appropriate flags to manage pause times and optimize performance.

E.g:

  Shared:
    extraJavaOpts: “-Xms2g -Xmx8g -XX:MaxGCPauseMillis=200
-XX:G1HeapRegionSize=16m”


4. Enable JMX Monitoring:

  • Java Management Extensions (JMX):
    • Enable JMX to allow monitoring and management of the JVM in real-time.
      -Dcom.sun.management.jmxremote
      -Dcom.sun.management.jmxremote.port=9010
      -Dcom.sun.management.jmxremote.authenticate=false
      -Dcom.sun.management.jmxremote.ssl=false

5. Optimize Thread Settings

  • Set Thread Stack Size:
    • Adjust the stack size for threads using the -Xss flag, based on the application requirements and the expected number of threads.

E.g:

  Shared:
       extraJavaOpts: “-Xms2g -Xmx8g -Xss1m”


  
6. Configure File Descriptors

  • Increase File Descriptors Limit:  Ensure the system allows a higher limit of file descriptors, especially in environments with many simultaneous connections.

    E.g for Linux:
        ulimit -n 10000

7.  Test and Monitor Changes

  • Test Configurations:
    Before applying changes to production, test configurations in a staging environment to ensure they do not negatively impact performance.
  • Continuous Monitoring:
    Continuously monitor the performance post-optimization to identify any further adjustments needed.

 

Conclusion

Optimizing the JVM settings for Artifactory can significantly enhance its performance and stability.
Regularly reviewing and tuning these settings in alignment with usage patterns and system capabilities will help maintain a responsive and efficient environment.
You can refer to this link for more information on JFrog Platform: Reference Architecture.