`
sillycat
  • 浏览: 2539127 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Page Cache(I)ehcache

阅读更多
Page Cache(I)ehcache

1. Theory
user -----> page -----> filter ----> action ----> service ----> dao -------> database

2. Configuration changes
timeToIdleSeconds       no requests for a time, ehcache will delete the cache data.
timeToLiveSeconds      cache live time from the creatation time

<cache name="SimplePageCachingFilter"
                maxElementsInMemory="10"
                maxElementsOnDisk="10"
                eternal="false"
                overflowToDisk="true"
                diskSpoolBufferSizeMB="20"
                timeToIdleSeconds="900"
                timeToLiveSeconds="900"
                memoryStoreEvictionPolicy="LFU"
              />
LFU will erase the data by the hits of the requests.

<filter>
<filter-name>IndexCacheFilter</filter-name>
<filter-class>
net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter
</filter-class>
<init-param>
      <param-name>cacheName</param-name>
      <param-value>SimplePageCachingFilter</param-value>
    </init-param>
</filter>
<filter-mapping>
<filter-name>IndexCacheFilter</filter-name>
<url-pattern>/index.do</url-pattern>
</filter-mapping>

cache policy
FIFO   first in first out
LFU     less frequently used
LRU    least recently used

3. Problems and Solutions
But get error messages:
2011-07-07 22:44:04,716 ERROR [net.xxxx.app.utils.Utility] (Timer-2) Exception while evicting elements
java.lang.NullPointerException
at net.xxxx.app.utils.Utility.evictExpiredElements(Utility.java:2241)
at org.jboss.scheduler30ss.EhCacheEvictScheduler.perform(EhCacheEvictScheduler.java:37)
at org.jboss.varia.scheduler.Scheduler$Listener.handleNotification(Scheduler.java:1251)
at sun.reflect.GeneratedMethodAccessor207.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.jboss.mx.notification.NotificationListenerProxy.invoke(NotificationListenerProxy.java:153)
at $Proxy316.handleNotification(Unknown Source)
at javax.management.NotificationBroadcasterSupport.handleNotification(NotificationBroadcasterSupport.java:274)
at javax.management.NotificationBroadcasterSupport$SendNotifJob.run(NotificationBroadcasterSupport.java:339)
at javax.management.NotificationBroadcasterSupport$1.execute(NotificationBroadcasterSupport.java:324)
at javax.management.NotificationBroadcasterSupport.sendNotification(NotificationBroadcasterSupport.java:247)
at javax.management.timer.Timer.sendNotification(Timer.java:1247)
at javax.management.timer.Timer.notifyAlarmClock(Timer.java:1209)
at javax.management.timer.TimerAlarmClock.run(Timer.java:1298)
at java.util.TimerThread.mainLoop(Timer.java:534)
at java.util.TimerThread.run(Timer.java:484)

Caused by: net.sf.ehcache.CacheException: Error configuring from /home/luohua/tools/jboss/30ss/ehcache.xml.
Initial cause was Error configuring from input stream. Initial cause was null:509:
Element <cache> does not allow attribute "momoryStoreEvictionPolicy".

Solution:
This is my project problem. My project already use ehcache in the system.
It will create the CacheManager from a configuration file this way:
cm = CacheManager.create(configuration_file_directory + "/ehcache.xml");

That is the problem. So I will customized the filter class like this CustomerSimplePageCachingFilter.java:
package com.xxxxx.web.filter;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter;
import net.xxx.xxxx.utils.Utility;

public class CustomerSimplePageCachingFilter extends SimplePageCachingFilter {

protected CacheManager getCacheManager() {
return Utility.getCacheManager();
}
}

Performance Test
>ab -n 1000 -c 50 http://localhost:8080/project/index.do >> log1.txt
>ab -n 1000 -c 50 http://localhost:8080/project/index.do >> log2.txt

error message:
apr_poll: The timeout specified has expired (70007)

solution:
This a bug from ab maybe, I just change the -n to a small number.

The comparation of the test results log1.txt:
Concurrency Level:      50
Time taken for tests:   84.977 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      3444000 bytes
HTML transferred:       3055000 bytes
Requests per second:    11.77 [#/sec] (mean)
Time per request:       4248.845 [ms] (mean)
Time per request:       84.977 [ms] (mean, across all concurrent requests)
Transfer rate:          39.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.3      0       8
Processing:  2179 4201 704.5   4095    8009
Waiting:     2178 4201 704.5   4095    8009
Total:       2181 4201 704.5   4095    8009

Percentage of the requests served within a certain time (ms)
  50%   4095
  66%   4286
  75%   4425
  80%   4531
  90%   4960
  95%   5591
  98%   6454
  99%   6950
100%   8009 (longest request)

log2.txt:
Concurrency Level:      50
Time taken for tests:   0.709 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      3218000 bytes
HTML transferred:       2975000 bytes
Requests per second:    1410.30 [#/sec] (mean)
Time per request:       35.453 [ms] (mean)
Time per request:       0.709 [ms] (mean, across all concurrent requests)
Transfer rate:          4431.98 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0       3
Processing:     1   34  22.3     30     181
Waiting:        1   34  22.2     30     165
Total:          2   34  22.7     30     184

Percentage of the requests served within a certain time (ms)
  50%     30
  66%     37
  75%     41
  80%     43
  90%     56
  95%     75
  98%     87
  99%    159
100%    184 (longest request)

references:
http://ahuaxuan.iteye.com/blog/128458
http://wiki.springside.org.cn/display/calvin/Ehcache
http://hi.baidu.com/luohuazju/blog/item/b9ac3e51803fe7858d543026.html
http://ehcache.org/documentation/samples.html#Cache_Server_Examples

分享到:
评论

相关推荐

    Spring4 整合EhCache实现 页面缓存 零配置

    当`getPage`方法被调用时,如果`pageCache`中存在相同键的缓存,则直接返回,否则执行方法并将其结果存入缓存。 对于页面局部缓存,你可以使用相同的方式,只需为不同的部分创建不同的缓存名称,并在需要的地方应用...

    springmodules-cache.xsd&springmodules-ehcache.xsd.rar

    解决web.xml中 &lt;page-encoding&gt;UTF-8&lt;/page-encoding&gt;报错。错误提示: cvc-complex-type.2.4.a: Invalid content was found starting with element 'page-encoding'. One of '{"http:// java.sun....

    ehcache缓存页面

    接下来,我们将缓存集成到Web应用中,通常是在`page-filter-action-service-dao-db`架构中。页面缓存的理想位置是靠近客户端,即在`filter`层。当第一个用户请求页面后,页面被缓存。后续用户请求时,过滤器可以直接...

    ehcache配置拦截器缓存页面

    &lt;cache alias="pageCache"&gt; &lt;key-type&gt;java.lang.String &lt;value-type&gt;java.lang.String &lt;heap unit="MB"&gt;5 &lt;offheap unit="MB"&gt;10 &lt;/cache&gt; ``` 然后,在Spring MVC项目中,我们需要创建一个自定义的...

    Hibernate二级缓存(Ehcache)

    &lt;property name="hibernate.cache.region.factory_class"&gt;org.hibernate.cache.ehcache.EhCacheRegionFactory ``` 接着,为了使特定的实体类使用二级缓存,我们需要在实体类上添加`@Cacheable`和`@Cache`注解: ``...

    ehcache模糊批量移除缓存的方法

    用 EL 表达式获取到参数中的 page,并作为缓存的 key,使用 @Cacheable 添加到 Ehcache 的缓存中。这时候,在缓存中就会出现 listOfTask_1 , listOfTask_2 , listOfTask_3 这种类型的 key。 当添加、删除任务时,...

    JAVA缓存技术_深入了解.ppt

    - **操作系统磁盘缓存**:操作系统自动管理的Disk Cache,如Windows的虚拟内存和Linux的Page Cache。 - **数据库缓存**:数据库管理系统内部的缓存机制,如MySQL的Query Cache和Data Buffer。 - **应用程序缓存**:...

    新建Web应用项目和集成Tomcat服务器.doc

    3. 在 index.jsp 页面中添加中文支持的标签,例如:&lt;%@ page contentType="text/html;charset=gb2312" isELIgnored="false"%&gt; 四、设置中文支持 在 MyEclipse 中,可以改变默认的编码方式,例如将 encoding 项目...

    JAVAStruts语音视频教程分页显示数据WEB开发最好方法

    9. **性能优化**:为了提高性能,可以使用缓存技术,如Spring的Cache或Ehcache,来缓存查询结果,减少不必要的数据库访问。 10. **错误和异常处理**:在处理分页请求时,应考虑可能出现的错误情况,如非法的页码值...

    在Jsp中怎样清空缓存 了解就可以了

    例如,Ehcache 可以通过 `cacheManager.getCache().removeAll()` 来清除所有缓存项。 总之,清空JSP的缓存涉及到客户端和服务器端的不同层面,理解这些机制有助于我们在开发过程中快速解决因缓存导致的问题。在实际...

    JSP 动态数据菜单.rar

    为了提高性能,菜单数据可以缓存在内存中,比如使用Spring Cache或者Ehcache。当菜单数据发生更改时,更新缓存内容。 综上所述,JSP动态数据菜单的实现涉及到了多个环节,从JSP基础、数据库交互、Java集合操作到...

    框架整合SSH实现分页

    8. **优化**:考虑性能优化,可以使用缓存技术如Spring Cache或 EhCache,缓存部分不常变动的数据,减少数据库查询次数。此外,还可以利用Spring的懒加载特性,避免一次性加载过多数据。 通过以上步骤,我们可以...

    Java Web 应用开发-分页小程序

    7. **缓存优化**:为了提高性能,可以考虑使用缓存机制,如内存缓存(如 Ehcache)或数据库缓存(如 MySQL 的 Query Cache),减少不必要的数据库查询。 8. **响应式设计**:确保分页小程序在不同设备和屏幕尺寸上...

    dihaw-spring-security

    dihaw-spring-security Maven Spring MVC 应用程序 ...* Ehcache: in order to optimize the database access and the cache of the application * logback: Logback is intended as a successor to the popul

    dihaw-spring-security:Spring MVC 和 Spring 安全

    dihaw-spring-security Maven Spring MVC 应用程序 ...* Ehcache: in order to optimize the database access and the cache of the application * logback: Logback is intended as a successor to the popul

    spring-mvc-formation:Spring MVC 应用程序

    spring-mvc-形成 Spring MVC 应用程序 ...* Ehcache: in order to optimize the database access and the cache of the application * logback: Logback is intended as a successor to the popular log4j projec

    提升Web 应用系统性能研究

    - **使用JSP指令和脚本**:合理利用JSP指令和脚本来控制页面的行为,如使用`&lt;%@ page %&gt;`指令设置页面的编码、错误处理等;使用`&lt;% %&gt;`脚本块执行Java代码逻辑。 - **减少数据库查询次数**:通过缓存机制减少对...

    spring-boot-reference.pdf

    I. Spring Boot Documentation 1. About the Documentation 2. Getting Help 3. First Steps 4. Working with Spring Boot 5. Learning about Spring Boot Features 6. Moving to Production 7. Advanced Topics II....

Global site tag (gtag.js) - Google Analytics