⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resin-clustering.xtp

📁 RESIN 3.2 最新源码
💻 XTP
📖 第 1 页 / 共 3 页
字号:
needed for jdbc-store sessions.  tcp-store sessions use a more-sophisticatedprotocol that eliminates the need for always-load-session, so tcp-storeignores the always-load-session flag.</p><p>The <var>always-load-session</var> attribute forces sessions to check the store foreach request.  By default, sessions are only loaded from persistentstore when they are created.  In a configuration with multiple symmetricweb servers, sessions can be loaded on each request to ensure consistency.</p></s2><s2 title="always-save-session"><p>By default, Resin only saves session data when you add new valuesto the session object, i.e. if the request calls <var>setAttribute</var>.This may be insufficient when storing large objects.  For example, if youchange an internal field of a large object, Resin will not automaticallydetect that change and will not save the session object.</p><p>With <var>always-save-session</var> Resin will always write the sessionto the store at the end of each request.  Although this is less efficient,it guarantees that updates will get stored in the backup after eachrequest.</p></s2></s1><s1 title="Database Based"><p>Database backed sessions are the easiest to understand.  Session datagets serialized and stored in a database.  The data is loaded on thenext request.</p><p>For efficiency, the owning JVM keeps a cache of the session value, soit only needs to query the database when the session changes.  If another JVMstores a new session value, it will notify the owner of the change sothe owner can update its cache.  Because of this notification, the databasestore is cluster-aware.</p><p>In some cases, the database can become a bottleneck.By adding load to an already-loadedsystem, you may harm performance.  One way around that bottleneck is to usea small, quick database like MySQL for your session store and save the "BigIron" database like Oracle for your core database needs.</p><p>The database must be specified using a <var>&lt;database&gt;</var>.The database store will automatically create a <var>session</var> table.</p><p>The JDBC store needs to know about the other servers in the clusterin order to efficiently update them when changes occur to the server.</p><example title="JDBC store">&lt;resin xmlns="http://caucho.com/ns/resin"&gt;&lt;cluster id="app-tier"&gt;  &lt;server-default>    &lt;http port="80"/>  &lt;/server-default>  &lt;server id="app-a" address="192.168.2.10" port="6800"/>  &lt;server id="app-b" address="192.168.2.11" port="6800"/>  &lt;database jndi-name="jdbc/session"&gt;    ...  &lt;/database&gt;  &lt;persistent-store type="jdbc"&gt;    &lt;init&gt;      &lt;data-source&gt;jdbc/session&lt;data-source&gt;    &lt;/init&gt;  &lt;/persistent-store&gt;  ...  &lt;web-app-default&gt;    &lt;session-config&gt;      &lt;use-persistent-store/&gt;    &lt;/session-config&gt;  &lt;/web-app-default&gt;  ...&lt;/cluster>&lt;/resin></example><p>The persistent store is configured in the &lt;server&gt; with<a href="resin-tags.xtp#persistent-store">persistent-store</a>.Each web-app which needs distributed sessions must enablethe persistent store with a<a href="webapp-tags.xtp#session-config">use-persistent-store</a>tag in the session-config.</p><deftable><tr>  <td>data-source</td>  <td>data source name for the table</td></tr><tr>  <td>table-name</td>  <td>database table for the session data</td></tr><tr>  <td>blob-type</td>  <td>database type for a blob</td></tr><tr>  <td>max-idle-time</td>  <td>cleanup time</td></tr></deftable><example>CREATE TABLE persistent_session (  id VARCHAR(64) NOT NULL,  data BLOB,  access_time int(11),  expire_interval int(11),  PRIMARY KEY(id))</example><p>The store is enabled with &lt;use-persistent-store&gt; in the session config.</p><example>&lt;web-app xmlns="http://caucho.com/ns/resin"&gt;  &lt;session-config&gt;    &lt;use-persistent-store/&gt;    &lt;always-save-session/&gt;  &lt;/session-config&gt;&lt;/web-app&gt;</example></s1><s1 title="Cluster Sessions"><p>The distributed cluster stores the sessions across thecluster servers.  In some configurations, the cluster storemay be more efficient than the database store, in others the databasestore will be more efficient.</p><p>With cluster sessions, each session has an owning JVM and a backup JVM.The session is always stored in both the owning JVM and the backup JVM.</p><p>The cluster store is configured in the in the &lt;cluster&gt;.It uses the &lt;server&gt; hosts in the &lt;cluster&gt; to distributethe sessions.  The session store is enabled in the &lt;session-config&gt;with the &lt;use-persistent-store&gt;.</p><example>&lt;resin xmlns="http://caucho.com/ns/resin"&gt;  ...  &lt;cluster id="app-tier"&gt;    &lt;server id="app-a" host="192.168.0.1" port="6802"/>    &lt;server id="app-b" host="192.168.0.2" port="6802"/>    &lt;persistent-store type="cluster"&gt;      &lt;init path="cluster"/&gt;    &lt;/persistent-store&gt;    ...  &lt;/cluster>&lt;/resin></example><p>The configuration is enabled in the <var>web-app</var>.</p><example>&lt;web-app xmlns="http://caucho.com/ns/resin"&gt;  &lt;session-config&gt;    &lt;use-persistent-store="true"/&gt;  &lt;/session-config&gt;&lt;/web-app&gt;</example><p>The &lt;srun&gt; and &lt;srun-backup&gt; hosts are treated as a clusterof hosts.  Each host uses the other hosts as a backup.  When the sessionchanges, the updates will be sent to the backup host.  When the host starts, itlooks up old sessions in the other hosts to update its own version of thepersistent store.</p><example title="Symmetric load-balanced servers">&lt;resin xmlns="http://caucho.com/ns/resin"&gt;&lt;cluster id="app-tier"&gt;  &lt;server-default&gt;    &lt;http port='80'/&gt;  &lt;/server-default&gt;  &lt;server id="app-a" address="192.168.2.10" port="6802"/>  &lt;server id="app-b" address="192.168.2.11" port="6803"/>  &lt;persistent-store type="cluster"&gt;    &lt;init path="cluster"/&gt;  &lt;/persistent-store&gt;  &lt;host id=''&gt;  &lt;web-app id=''&gt;  &lt;session-config&gt;    &lt;use-persistent-store="true"/&gt;  &lt;/session-config&gt;  &lt;/web-app&gt;  &lt;/host&gt;&lt;/cluster&gt;&lt;/resin&gt;</example></s1><s1 title="Clustered Distributed Sessions"><p>Resin's cluster protocol for distributed sessions canis an alternative to JDBC-based distributed sessions.  In someconfigurations, the cluster-stored sessions will be more efficientthan JDBC-based sessions.Because sessions are always duplicated on separate servers, clustersessions do not have a single point of failure.As the number ofservers increases, JDBC-based sessions can start overloading thebacking database.  With clustered sessions, each additional servershares the backup load, so the main scalability issue reduces to networkbandwidth.  Like the JDBC-based sessions, the cluster store sessionsuses sticky-session caching to avoid unnecessary network traffic.</p></s1><s1 title="Configuration"><p>The cluster configuration must tell each host the servers in theclusterand it must enable the persistent in the session configurationwith <a href="session-tags.xtp#session-config">use-persistent-store</a>.Because session configuration is specific to a virtual host and aweb-application, each web-app needs <var>use-persistent-store</var> enabledindividually.  The <a href="webapp-tags.xtp#web-app-default">web-app-default</a>tag can be used to enable distributed sessions across an entire site.</p><p>Most sites using Resin's load balancing will already have the cluster<var>&lt;srun&gt;</var> configured.  Each <var>&lt;srun&gt;</var> block corresponds to ahost, including the current host.  Since cluster sessions usesResin's srun protocol, each host must listen for srun requests.</p><example title="resin.xml fragment">&lt;resin xmlns="http://caucho.com/ns/resin">  &lt;cluster id="app-tier"&gt;    &lt;server id="app-a" host="192.168.0.1"/>    &lt;server id="app-b" host="192.168.0.2"/>    &lt;server id="app-c" host="192.168.0.3"/>    &lt;server id="app-d" host="192.168.0.4"/>    &lt;persistent-store type="cluster"&gt;      &lt;init path="cluster"/&gt;    &lt;/persistent-store&gt;    ...    &lt;host id=""&gt;    &lt;web-app id='myapp'&gt;      ...      &lt;session-config&gt;        &lt;use-persistent-store/&gt;      &lt;/session-config&gt;    &lt;/web-app&gt;    &lt;/host&gt;  &lt;/cluster&gt;&lt;/resin&gt;</example><p>Usually, hosts will share the same resin.xml.  Each host will bestarted with a different <var>-server xx</var> to select the correctblock.  On Unix, startup will look like:</p><example title="Starting Host&#160;C on Unix">resin-3.2.x&gt; bin/resin.sh -conf conf/resin.xml -server c start</example><p>On Windows, Resin will generally be configured as a service:</p><example title="Starting Host&#160;C on Windows">resin-3.2.x&gt; bin/resin -conf conf/resin.xml -server c -install-as ResinC</example><s2 title="always-save-session"><p>Resin's distributed sessions needs to know when a session haschanged in order to save the new session value.  Although Resin candetect when an application calls <var>HttpSession.setAttribute</var>, itcan't tell if an internal session value has changed.  The followingCounter class shows the issue:</p><example title="Counter.java">package test;public class Counter implements java.io.Serializable {  private int _count;  public int nextCount() { return _count++; }}</example><p>Assuming a copy of the Counter is saved as a session attribute,Resin doesn't know if the application has called <var>nextCount</var>.  If itcan't detect a change, Resin will not backup the new session, unless<var>always-save-session</var> is set.  When <var>always-save-session</var> istrue, Resin will back up the session on every request.</p><example>...&lt;web-app id="/foo"&gt;...&lt;session-config&gt;  &lt;use-persistent-store/&gt;  &lt;always-save-session/&gt;&lt;/session-config&gt;...&lt;/web-app&gt;</example><p>Like the JDBC-based sessions, Resin will ignore the<var>always-load-session</var> flag for cluster sessions.  Because thecluster protocol notifies servers of changes, <var>always-load-session</var> isnot needed.</p></s2><s2 title="Serialization"><p>Resin's distributed sessions relies on Java serialization to save andrestore sessions.  Application object must <var>implementjava.io.Serializable</var> for distributed sessions to work.</p></s2></s1><s1 title="Protocol Examples"><s2 title="Session Request"><p>To see how cluster sessions work, consider a case wherethe load balancer sends the request to a random host.  Host&#160;C owns thesession but the load balancer gives the request to Host&#160;A.  In thefollowing figure, the request modifies the session so it must be savedas well as loaded.</p><figure src="srunc.gif"/><p>The session id encodes the owning host.  The example sessionid, <var>ca8MbyA</var>, decodes to an srun-index of 3, mappingto Host&#160;C.  Resin determines the backup host from the cookieas well.Host&#160;A must know the owning hostfor every cookie so it can communicate with the owning srun.The example configuration defines all the sruns Host&#160;A needs toknow about.  If Host&#160;C is unavailable, Host&#160;A can use itsconfiguration knowledge to use Host&#160;D as a backupfor <var>ca8MbyA</var> instead..</p><p>When the request first accesses the session, Host&#160;A asksHost&#160;C for the serialized session data (<var>2:load</var>).Since Host&#160;A doesn't cache the session data, it mustask Host&#160;C for an update on each request.  For requests thatonly read the session, this TCP load is the only extra overhead,i.e. they can skip <var>3-5</var>.  The <var>always-save-session</var>flag, in contrast, will always force a write.</p><p>At the end of the request, Host&#160;A writes any sessionupdates to Host&#160;C (<var>3:store</var>). If always-save-sessionis false and the session doesn't change, this step can be skipped.Host&#160;A sendsthe new serialized session contents to Host&#160;C.  Host&#160;C savesthe session on its local disk (<var>4:save</var>) and saves a backupto Host&#160;D (<var>5:backup</var>).</p></s2><s2 title="Sticky Session Request"><p>Smart load balancers that implement sticky sessions can improvecluster performance.  In the previous request, Resin's clustersessions maintain consistency for dumb load balancers or twistedclients like the AOL browsers.  The cost is the additional network

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -