2008年12月17日水曜日

[Grails]Integration Terracotta(Java VM Clustering) with Grails manually

Steps to Integrate the Terracotta(Java VM Clustering) with Grails manually without using the Terracotta plugin.
  • References
  • Steps
    • Install Java development kit
    • Install latest grails
    • Install latest terracotta
    • Create terracotta's config file as follows
      (Following is a example configuration, please refer to the terracotta documentation about the detail of the config file)
      Following configuration is clustered the util.cache.Cache.cacheMap object, and set the named-lock for all the methods.
      <?xml version="1.0" encoding="UTF-8"?>
      <tc:tc-config xmlns:tc="http://www.terracotta.org/config"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-4.xsd">

      <servers>
      <server name="server1" host="localhost">
      <data>%(user.home)/terracotta/server-data</data>
      <logs>%(user.home)/terracotta/server-logs</logs>
      <dso>
      <client-reconnect-window>10</client-reconnect-window>
      <persistence>
      <mode>temporary-swap-only</mode>
      </persistence>
      <garbage-collection>
      <enabled>true</enabled>
      <verbose>false</verbose>
      <interval>180</interval>
      </garbage-collection>
      </dso>
      <jmx-port>9520</jmx-port>
      <l2-group-port>9530</l2-group-port>
      </server>
      </servers>

      <clients>
      <logs>%(user.home)/terracotta/client-logs</logs>
      </clients>

      <application>
      <dso>
      <roots>
      <root>
      <field-name>util.cache.Cache.cacheMap</field-name>
      </root>
      </roots>

      <instrumented-classes>
      <include>
      <class-expression>util.cache.Cache</class-expression>
      </include>
      </instrumented-classes>

      <locks>
      <named-lock>
      <lock-name>CacheMapWriteLock</lock-name>
      <lock-level>write</lock-level>
      <method-expression>* util.cache.Cache.clear(..)</method-expression>
      </named-lock>

      <named-lock>
      <lock-name>CacheMapWriteLock</lock-name>
      <lock-level>concurrent</lock-level>
      <method-expression>* util.cache.Cache.set(..)</method-expression>
      </named-lock>

      <named-lock>
      <lock-name>CacheMapWriteLock</lock-name>
      <lock-level>concurrent</lock-level>
      <method-expression>* util.cache.Cache.remove(..)</method-expression>
      </named-lock>

      <named-lock>
      <lock-name>CacheMapReadLock</lock-name>
      <lock-level>read</lock-level>
      <method-expression>* util.cache.Cache.get(..)</method-expression>
      </named-lock>

      <named-lock>
      <lock-name>CacheMapReadLock</lock-name>
      <lock-level>read</lock-level>
      <method-expression>* util.cache.Cache.contain(..)</method-expression>
      </named-lock>
      </locks>
      </dso>
      </application>
      </tc:tc-config>
    • Start the terracotta server
      ${TC_INSTALL_DIR}/bin/start-tc-server.sh -f (Set path to the terracotta config) -n (Set server name in terracotta config file)
    • Set the environment variables
      export JAVA_HOME=(Set JDK's home directory)
      export GRAILS_HOME=(Set Grails home directory)
      export JAVA_OPTS="(Set java option parameters if you need)"
      export TC_INSTALL_DIR=(Set Teraccotta's home directory)
      export JAVACMD="${TC_INSTALL_DIR}/bin/dso-java.sh"
      export JAVA_OPTS="$JAVA_OPTS -Dtc.config=(Set path to the terracotta config file)"
    • Start Grails web server
      grails -Dserver.port=(Set Port Number) run-app dev
      (When executing this command, jetty is started after grails command run the terracotta client and read the configration file because the JAVACMD environment variable is set to the terracotta shell script file)
    • Integration terracotta with the tomcat
      Please refer to the terracotta documentation for more detail.
      http://www.terracotta.org/web/display/orgsite/Tomcat+Integration

      Following is a sample tomcat startup script.
      JAVA_HOME="(top directory name installed the jdk)"
      JAVA_OPTS="-server -Xms256m -Xmx512m -Xss256k"
      TOMCAT_HOME="(top directory name installed the tomcat)"
      PATH="$PATH:$JAVA_HOME/bin:$ANT_HOME/bin:$TOMCAT_HOME/bin"

      TC_INSTALL_DIR="(directory name installed the terracotta)"
      TC_CONFIG_PATH="(full path name of the terracotta configuration file.)"
      . $TC_INSTALL_DIR/bin/dso-env.sh -q
      export JAVA_OPTS="$TC_JAVA_OPTS $JAVA_OPTS"
      sh ${TOMCAT_HOME}/bin/catalina.sh start
    • Integration terracotta with jetty
      Please refer to the terracotta documentation.
      http://www.terracotta.org/web/display/orgsite/Jetty+Integration

0 件のコメント: