Customized Azure site Java Runtime Environment (3)

Source: Internet
Author: User

Customized Azure site Java Runtime Environment (3)
Customized default Tomcat and JDK environments provided by Azure Website

In our previous tests, if no context is added when you access the URL of your WEB site, the web interface you see is the index of the test page that comes with the system. jsp, located in the/site/wwwroot/webapps/ROOT directory, is the default Tomcat ROOT directory.

To check the JVM usage information to determine whether the modified Java parameters take effect, we need to write some test code to print the current JVM parameter information; first, use FileZilla to connect to your website, go to the/site/wwwroot/webapps/ROOT directory, and download index. jsp file to local.

I wrote a simple test program to test the heap size during Java runtime. The JVM parameters obtained using ManagmentBeans have been uploaded to github. Please download them directly, or you can open the index. the code for adding a jsp file is as follows:

Https://github.com/kingliantop/azurelabs/blob/master/Java/websites/index.jsp

<[email protected]="java.util.*"%><[email protected]="java.lang.management.*"%><%ArrayList
 
  mainPageProps=newArrayList
  
   ();mainPageProps.add("java.version");mainPageProps.add("java.vendor");mainPageProps.add("os.arch");mainPageProps.add("catalina.base");mainPageProps.add("jetty.base");mainPageProps.add("user.timezone");for(Stringname:mainPageProps){Stringvalue=System.getProperty(name);if(value!=null){out.print(""+name);out.print(""+value);out.print("");}}intMB=1024*1024;Runtimeruntime=Runtime.getRuntime();out.print("RuntimeTotalmemory:"+runtime.totalMemory()/MB+"M");out.print("RuntimeFreememory:"+runtime.freeMemory()/MB+"M");out.print("RuntimeUsedmemory:"+(runtime.totalMemory()-runtime.freeMemory())/MB+"M");out.print("RuntimeMaxmemory:"+runtime.maxMemory()/MB+"M");Iteratoriter=ManagementFactory.getMemoryPoolMXBeans().iterator();out.print("MemoryMXBean");out.print("HeapMemoryUsage:"+ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()+"");out.print("Non-HeapMemoryUsage:"+ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage()+"");out.print("MemoryPoolMXBeans");while(iter.hasNext()){MemoryPoolMXBeanitem=(MemoryPoolMXBean)iter.next();out.print("
   "+item.getName()+"");out.print("Type:"+item.getType()+"");out.print("Usage:"+item.getUsage()+"");out.print("PeakUsage:"+item.getPeakUsage()+"");out.print("CollectionUsage:"+item.getCollectionUsage()+"");}%>
  
 

3. upload the modified index. the jsp file is in the ROOT directory, overwrite the original file, and re-open your web site homepage. You can see that the test program prints the memory size, heap size, and, non-heap size and other related information:

4. we can see that the initial Heap size in the default runtime environment is 28664 kb, about 54 M is used, the maximum content usage is 433 M, and the size of the website instance used in the current testing environment is small, it is about a core, 1.75G memory:

For the PermGen size, the initial size is:

Init = 22020096 (21504 K) used = 41871616 (40890 K) committed = 41943040 (40960 K) max = 85983232 (83968 K)

 

5. in a simple experiment, we will upgrade the web site instance to see if Azure website will automatically adjust JVM parameters based on the current system instance size. On the "zoom" page, we will upgrade the instance to a medium-sized instance and click Save:

At this time, you will see that the default heap size has also changed:

So how does Azure adjust the running environment and configuration of Tomcat? How can we achieve this dynamic adjustment?

In fact, there is no magic. The bottom layer of Azure website is Windows Server. IIS is used to manage other third-party servers, such as Tomcat. IIS has a management module called HttpPlatformHandler, which will do the following:

  1. All third-party application servers that directly process Http requests, such as Tomcat, Jetty, and Node. JS, are accepted by IIS.

    All requests taken over by IIS are forwarded to the backend servers, such as Tomcat, which are similar to Nginx and apache httpd.

    Manage third-party programs, start third-party programs, set startup parameters, and customize the corresponding environment. All these operations are implemented through a file called web. config.

    You can see through the above introduction that on the PAAS platform of Azure website, if we need to deploy customized environments, we need to use this mechanism, which is implemented by HttpPlatformHandler through the web. config configuration file.

    In this test scenario, we assume that you need to modify the heap size and PermGen size in the default runtime environment, because the OutOfMemory error occurs in common Java application errors, some are caused by the small PermGen size.

    1. First, we need to prepare a web. config file. In this example, we use the Tomcat and JDK provided by the Azure site. We need to configure the relevant parameters-Xms512m-Xmx1024m-XX: PermSize = 128 m-XX: maxPermSize = 256m placed under JAVA_OPTS:

           
           
            
             
             
              
               
                
               
              
             
            
            

      Note:

      1. The default system tomcat path is "% AZURE_TOMCAT7_HOME % \ bin \ startup. bat". Be sure to set it correctly.

        Java-related parameter settings are placed in JAVA_OPTS, such as-Xms and-Xmx.

        2. Record the Heap size and PermGen size settings under the default settings. Refresh the test page and you will see:

        Heap Size:Heap Memory Usage: init = 58712896 (57336 K) used = 150252200 (146730 K) committed = 360710144 (352256 K) max = 835190784 (815616 K)

        Perm Gen:

        Usage: init = 22020096 (21504 K) used = 42138168 (41150 K) committed = 42467328 (41472 K) max = 85983232 (83968 K)

        3. Use your FTP tool to upload the web. config file to your Azure site root directory/site/wwwroot:

        4. Refresh the page and you will see that the JVM parameter value has changed:

        Heap Memory Usage: init = 536870912 (524288 K) used = 118235616 (115464 K) committed = 660602880 (645120 K) max = 954728448 (932352 K)

         

        Usage: init = 134217728 (131072 K) used = 37151352 (36280 K) committed = 134217728 (131072 K) max = 268435456 (262144 K)

        We can see that the Azure site can be customized through the web. config and HttpPlatformHandler mechanisms.

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.