Resin服務器簡介、Resin服務器配置說明、Resin配置鏈接池

一.Resin服務器簡介

稍後補:php

一、稍後補;html

二、稍後補;java

 

二.Resin服務器配置說明(resin.conf配置詳解)

<!--
   - Resin 3.1 configuration file.
   - Resin 3.1 配置文件
  -->
<resin xmlns="http://caucho.com/ns/resin"
       xmlns:resin="http://caucho.com/ns/resin/core">

  <!-- adds all .jar files under the resin/lib directory -->
  <!-- 加載resin/lib下的全部.jar文件 -->
  <class-loader>
    <tree-loader path="${resin.home}/ext-lib"/>
    <tree-loader path="${resin.root}/ext-lib"/>

    <tree-loader path="${resin.home}/lib"/>
    <tree-loader path="${resin.root}/lib"/>
  </class-loader>

  <!--
     - Management configuration
     - 管理配置
     -
     - Remote management requires at least one enabled admin user.
    -->
  <management path="${resin.root}/admin">
    <user name="admin" password="password" disable="true"/>

    <resin:if test="${resin.professional}">
      <deploy-service/>
      <jmx-service/>
      <log-service/>
      <xa-log-service/>
    </resin:if>
  </management>

  <!--
     - Logging configuration for the JDK logging API.
     - JDK日誌接口的配置
    -->
  <log name="" level="info" path="stdout:"
       timestamp="[%H:%M:%S.%s] {%{thread}} "/>

  <!--
     - 'info' for production
     - 'fine' or 'finer' for development and troubleshooting
     - 日誌信息的級別:'info' 生產環境 'fine' 開發環境 'finer' 調試環境
    -->
  <logger name="com.caucho" level="info"/>

  <logger name="com.caucho.java" level="config"/>
  <logger name="com.caucho.loader" level="config"/>

  <!--
     - For production sites, change dependency-check-interval to something
     - like 600s, so it only checks for updates every 10 minutes.
     - 環境上下文的檢測時間,對於生產站點, 這個要設置長一點,例如600秒,10分鐘
    -->
  <dependency-check-interval>2s</dependency-check-interval>

  <!--
     - SMTP server for sending mail notifications
     - 發送郵件通知的SMTP服務器
    -->
  <system-property mail.smtp.host="127.0.0.1"/>
  <system-property mail.smtp.port="25"/>

  <!--
     - Sets the default character encoding to utf-8
     -
     - <character-encoding>utf-8</character-encoding>
    -->

  <!--
     - You can change the compiler to "javac", "eclipse" or "internal".
     - 你能夠把編譯器改爲 "javac", "eclipse" 或者 "internal"
    -->
  <javac compiler="internal" args="-source 1.5"/>

  <!-- Security providers.
     - <security-provider>
     -    com.sun.net.ssl.internal.ssl.Provider
     - </security-provider>
    -->

  <!-- Uncomment to use Resin's XML implementations
     - 去掉註釋,若是你使用resin提供的xml應用
     -
     - <system-property javax.xml.parsers.DocumentBuilderFactory
     -                 ="com.caucho.xml.parsers.XmlDocumentBuilderFactory"/>
     - <system-property javax.xml.parsers.SAXParserFactory
     -                 ="com.caucho.xml.parsers.XmlSAXParserFactory"/>
    -->

  <cluster id="app-tier">
    <!-- sets the content root for the cluster, relative to server.root -->
    <!-- 設置集羣上下文的根, 相對於server.root -->
    <root-directory>.</root-directory>

    <server-default>
      <!-- The http port -->
      <!-- HTTP服務的端口 -->
      <http address="*" port="8080"/>

      <!--
         - SSL port configuration:
         - SSL端口配置
         -
         - <http address="*" port="8443">
         -   <openssl>
         -     <certificate-file>keys/gryffindor.crt</certificate-file>
         -     <certificate-key-file>keys/gryffindor.key</certificate-key-file>
         -     <password>test123</password>
         -   </openssl>
         - </http>
        -->

      <!--
         - The JVM arguments
         - JVM參數設置
        -->
      <jvm-arg>-Xmx256m</jvm-arg>
      <jvm-arg>-Xss1m</jvm-arg>
      <jvm-arg>-Xdebug</jvm-arg>
      <jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>

      <!--
         - Uncomment to enable admin heap dumps
         - 去掉這個若是你想管理內存堆的傾倒
         - <jvm-arg>-agentlib:resin</jvm-arg>
        -->

      <!--
         - arguments for the watchdog process
        -->
      <watchdog-jvm-arg>-Dcom.sun.management.jmxremote</watchdog-jvm-arg>
      <watchdog-port>6600</watchdog-port>

      <!--
         - Configures the minimum free memory allowed before Resin
         - will force a restart.
         - 強制resin強制重起時的最小空閒內存
        -->
      <memory-free-min>1M</memory-free-min>

      <!-- Maximum number of threads. -->
      <!-- 最大線程數量 -->
      <thread-max>256</thread-max>

      <!-- Configures the socket timeout -->
      <!-- 套接字等待時間 -->
      <socket-timeout>65s</socket-timeout>

      <!-- Configures the keepalive -->
      <!-- 配置 keepalive -->
      <keepalive-max>128</keepalive-max>
      <keepalive-timeout>15s</keepalive-timeout>

      <!--
         - If starting bin/resin as root on Unix, specify the user name
         - and group name for the web server user.
         - 若是使用的是UNIX,這裏是啓動的賬號和用戶組
         -
         - <user-name>resin</user-name>
         - <group-name>resin</group-name>
        -->
    </server-default>

    <!-- define the servers in the cluster -->
    <!-- 定義羣集服務器 -->
    <server id="" address="127.0.0.1" port="6800"/>

    <!--
       - Configures the persistent store for single-server or clustered
       - in Resin professional.
       - 配置獨立服務器或者羣集的持久化存儲,專業版的功能
      -->
    <resin:if test="${resin.professional}">
      <persistent-store type="cluster">
        <init path="session"/>
      </persistent-store>
    </resin:if>

    <!--
       - For security, use a different cookie for SSL sessions.
       - 爲了安全, 你能夠爲SSL會話(SSL sessions)定義一個不一樣的cookie
       - <ssl-session-cookie>SSL_JSESSIONID</ssl-session-cookie>
      -->

    <!--
       - Enables the cache (available in Resin Professional) 
       - 緩存啓用 (專業版的功能)
      -->
    <resin:if test="${resin.professional}">
      <cache path="cache" memory-size="64M">
        <!-- Vary header rewriting for IE -->
        <rewrite-vary-as-private/>
      </cache>
    </resin:if>

    <!--
       - Enables periodic checking of the server status and
       - check for deadlocks..
       -
       - All servers can add <url>s to be checked.
       - 啓用週期性的服務器狀態檢查和死鎖檢查,全部的服務器能夠添加 <url> 來檢查
      -->
    <resin:if test="${resin.professional}">
      <ping>
        <!-- <url>http://localhost:8080/test-ping.jsp</url> -->
      </ping>
    </resin:if>

    <!--
       - Defaults applied to each web-app.
       - 每個web應用的默認參數
      -->
    <web-app-default>
      <prologue>
        <!--
           - Extension library for common jar files.  The ext is safe
           - even for non-classloader aware jars.  The loaded classes
           - will be loaded separately for each web-app, i.e. the class
           - itself will be distinct.
           - 擴展庫的公共jar文件,擴展是安全的即便沒有類裝載器知道的jars,裝載的類將爲每一個應用分別裝載,也就是這些類都是不一樣的
          -->
        <class-loader>
          <tree-loader path="${resin.root}/ext-webapp-lib"/>
        </class-loader>

        <!--
           - Enable EL expressions in Servlet and Filter init-param
           - 啓用EL表達式
          -->
        <allow-servlet-el/>
      </prologue>
      
      <!--
         - Sets timeout values for cacheable pages, e.g. static pages.
         - 設置緩存頁、靜態也的延時值
        -->
      <cache-mapping url-pattern="/" expires="5s"/>
      <cache-mapping url-pattern="*.gif" expires="60s"/>
      <cache-mapping url-pattern="*.jpg" expires="60s"/>
      <cache-mapping url-pattern="*.png" expires="60s"/>

      <!--
         - for security, disable session URLs by default.
         - 安全緣由, 默認禁用了會話的URLs
        -->
      <session-config>
        <enable-url-rewriting>false</enable-url-rewriting>
      </session-config>

      <!--
         - For security, set the HttpOnly flag in cookies.
         - 安全緣由, 在cookies中設置HttpOnly標誌
         - <cookie-http-only/>
        -->

      <!--
         - Some JSP packages have incorrect .tld files.  It's possible to
         - set validate-taglib-schema to false to work around these packages.
         - 一些JSP包有不正確的 .tld文件。能夠把validate-taglib-schema設置成false,可能繼續正常工做
        -->
        <jsp>
          <validate-taglib-schema>true</validate-taglib-schema>
          <fast-jstl>true</fast-jstl>
        </jsp>
    </web-app-default>

    <!-- includes the app-default for default web-app behavior -->
    <!-- 包含web應用的默認行爲 -->
    <resin:import path="${resin.home}/conf/app-default.xml"/>

    <!--
       - Sample database pool configuration
       -
       - The JDBC name is java:comp/env/jdbc/test
       - 簡單的數據池配置
         <database>
           <jndi-name>jdbc/mysql</jndi-name>
           <driver type="org.gjt.mm.mysql.Driver">
             <url>jdbc:mysql://localhost:3306/test</url>
             <user></user>
             <password></password>
            </driver>
            <prepared-statement-cache-size>8</prepared-statement-cache-size>
            <max-connections>20</max-connections>
            <max-idle-time>30s</max-idle-time>
          </database>
      -->

    <!--
       - Default host configuration applied to all virtual hosts.
       - 定義全部虛擬主機的默認配置
      -->
    <host-default>
      <!--
         - With another web server, like Apache, this can be commented out
         - because the web server will log this information.
         - 若是和別的web服務器整合,這個能夠被去掉,由於web服務器也能夠記錄這些信息
        -->
      <access-log path="logs/access.log" 
            format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
            rollover-period="1W"/>

      <!-- creates the webapps directory for .war expansion -->
      <!-- war 文件的佈置目錄 -->
      <web-app-deploy path="webapps"/>

      <!-- creates the deploy directory for .ear expansion -->
      <!-- ear文件的佈置目錄 -->
      <ear-deploy path="deploy">
        <ear-default>
          <ejb-server>
            <config-directory>WEB-INF</config-directory>
          </ejb-server>
        </ear-default>
      </ear-deploy>

      <!-- creates the deploy directory for .rar expansion -->
      <!-- rar文件的佈置目錄 -->
      <resource-deploy path="deploy"/>
    </host-default>

    <!-- configures a deployment directory for virtual hosts -->
    <!-- 虛擬主機的佈置目錄 -->
    <host-deploy path="hosts">
      <host-default>
        <resin:import path="host.xml" optional="true"/>
      </host-default>
    </host-deploy>

    <!-- configures the default host, matching any host name -->
    <!-- 默認的虛擬主機配置 -->
    <host id="" root-directory=".">
      <!--
         - configures an explicit root web-app matching the
         - webapp's ROOT
         - 配置默認的應用 webapp's ROOT
        -->
      <web-app id="/" root-directory="webapps/ROOT"/>

      <web-app id="/resin-admin" root-directory="${resin.home}/php/admin">
        <!--
           - Administration application /resin-admin
           - 管理應用程序 /resin-admin
          -->
        <prologue>
          <resin:set var="resin_admin_external" value="false"/>
          <resin:set var="resin_admin_insecure" value="true"/>
        </prologue>
      </web-app>
    </host>
  </cluster>

  <!--
     - Configuration for the web-tier/load-balancer
    -->
  <resin:if test="${resin.professional}">
    <cluster id="web-tier">
      <server-default>
        <!-- The http port -->
        <http address="*" port="9080"/>
      </server-default>

      <server id="web-a" address="127.0.0.1" port="6700"/>

      <cache path="cache" memory-size="64M"/>

      <host id="">
        <web-app id="/">

           <rewrite-dispatch>
             <load-balance regexp="" cluster="app-tier"/>
           </rewrite-dispatch>

        </web-app>
      </host>
    </cluster>
  </resin:if>
</resin>

 

三.Resin配置鏈接池

鏈接池的概念:mysql

        在動態web站點設計中,數據庫已成爲必不可少的一部分,但數據庫鏈接和釋放開銷很大,對於一個訪問量少的網站可能沒有什麼影響,但同時有不少用戶來網站查詢資料時,就會致使服務器響應慢甚至死機。鏈接池就是針對這個問題提出的。
        數據庫鏈接池負責分配、管理和釋放數據庫鏈接容許應用程序重複使用一個現有的數據庫鏈接,而再不是從新創建一個釋放空閒時間超過最大空閒時間的數據庫鏈接來避免由於沒有釋放數據庫鏈接而引發的數據庫鏈接遺漏。這項技術能明顯提升對數據庫操做的性能。
        數據庫鏈接池在初始化時將建立必定數量的數據庫鏈接放到鏈接池中,這些數據庫鏈接的數量是由最小數據庫鏈接數來設定的。不管這些數據庫鏈接是否被使用,鏈接池都將一直保證至少擁有這麼多的鏈接數量。鏈接池的最大數據庫鏈接數量限定了這個鏈接池能佔有的最大鏈接數,當應用程序向鏈接池請求的鏈接數超過最大鏈接數量時,這些請求將被加入到等待隊列中。linux

resin中相關配置:        web

        Resin提供了一個良好的鏈接池來供開發人員來實現數據庫鏈接,具體配置以下,在/conf/resin.conf中<resin></resin>標籤中有如下內容:sql

<!--
       - Sample database pool configuration
       -
       - The JDBC name is java:comp/env/jdbc/test
         <database>
           <jndi-name>jdbc/mysql</jndi-name>
           <driver type="org.gjt.mm.mysql.Driver">
             <url>jdbc:mysql://localhost:3306/test</url>
             <user></user>
             <password></password>
            </driver>
            <prepared-statement-cache-size>8</prepared-statement-cache-size>
            <max-connections>20</max-connections>
            <max-idle-time>30s</max-idle-time>
          </database>
      -->

resin對具體參數的解析數據庫

結合案例分析上述參數,稍後補;express

 

四.與tomcat服務器性能比

一、移植性windows

    tomcat是參照標準J2EE實現,移植性會更好(對於老手來講tomcat和resin都同樣,固然不把EJB那包括進來)

二、速度

    resin的速度要比tomcat快3倍,官方的測試報告是針對resin-2.x與tomat4.x版本之前的比較了。

    resin的 啓動與關閉機制感受要比tomcat好不少,首先,tomcat在windows下啓動,雙擊完startup.bat後總要等幾秒鐘纔會啓動服務,而且 關閉的時候也是同樣的,有的時候甚至雙擊了shutdown.bat後startup.bat的窗口還老是在那好長時間,而且若是你哪一次不當心直接關閉 了dos窗口而沒有運行shutdown,那下一次確定要出問題,在linux下啓動速度仍是很不錯的,但若是啓動錯誤報錯真是很鬱悶。而相 反,resin的啓動就十分人性化了,運行httpd後會出來個窗口,其中有start和stop,你能夠隨時方便的啓動和關閉服務,而且速度也十分的 快,而且若是你的配置文件若是有改動的話,啓動程序會自動監測並自動重啓的,這樣在配置環境的時候就不須要像tomcat那樣須要反覆人工關閉再啓動,這 點tomcat真是差的很遠。

三、報錯機制

    resin更好的支持中文,更好的報錯機制。

     resin對於中文的支持要比 tomcat好不少,各類編碼和轉碼不少都是對tomcat設計的,由於在resin平臺下根本就不須要,這點對於開發也是很重要的,特別要提的一點就 是,用tomcat寫的面頁不少時候若是隻在面頁加上contentType="text/html; charset=gb2312"仍是不能完成編碼的還必需要加入一條看起來像是多此一舉的一條語句 request.setCharacterEncoding("gb2312"),這一點真實讓人不能忍受。

     tomcat的報錯機制,哪怕僅僅只是個小錯誤,tomcat都會用整頁的篇幅來描述,若是時間長了還好,但新手確定會望而生畏的,相反,resin的報錯是十分簡潔 而明確的,可讓你一眼就能夠看出程序錯誤的類型和位置,這點對於剛開始學習的人來講無疑是頗有幫助的。

四、方便性

    resin支持自動編譯 Servlet和Bean;

    tomcat還不支持j2ee,至少在5之前仍是這樣的;

五、成本

    我的認爲,對於企業來講,效率高和成本低的開發,才符合創造最大經濟消息的原則,用resin開發,通常的應用徹底能勝任。

相關文章
相關標籤/搜索