您的位置:首页 > 产品设计 > UI/UE

Ehcache 1.5.0 User Guide - Introduction (介绍)(1)

2009-06-17 15:48 477 查看


(Ehcache 1.5.0 用户指南)
E_mail:jianglike18@163.con
Blog: http://blog.csdn.net/jianglike18
qq:29396597

Introduction

Ehcache is a cache library. Before getting into ehcache, it is worth stepping back and thinking about caching.
(Ehcache 是一个缓存库,在了解Ehcache之前很值得返回去了解了解缓存。)

About Caches(关于缓存)
Wiktionary defines a cache as A store of things that will be required in future, and can be retrieved rapidly . That is the nub of it.
(维基词典定义了一个缓存存储以后需要东西并且可以快速的重新获取,关键就在这里。)

In computer science terms, a cache is a collection of temporary data which either duplicates data located elsewhere or is the result of a computation. Once in the cache, the data can be repeatedly accessed inexpensively.
(在计算机科学术语中,一个缓存就是一个临时数据的集合,临时数据可以是从其它地方复制的数据,也可以是计算的结果。一旦在缓存钟,数据就可以重复的廉价的访问。)

Why caching works(为什么缓存工作)
Locality of Reference(局部引用)
While ehcache concerns itself with Java objects, caching is used throughout computing, from CPU caches to the DNS system. Why? Because many computer systems exhibit locality of reference . Data that is near other data or has just been used is more likely to be used again.

(虽然ehcache关心Java对象,缓存的使用遍及整个计算,从CPU的缓存的DNS系统。为什么呢?由于许多计算机系统陈列局部引用。与其他数据接近或刚刚被使用的数据更容易被再次使用。)

The Long Tail is itself a vernacular term for a Power Law probability distribution. They don't just appear in ecommerce, but throughout nature. One form of a Power Law distribution is the Pareto distribution, commonly know as the 80:20 rule.
(通俗的讲,长尾本身是一种幂律概率分布。他们不只是出现在电子商务,而且在整个自然界。一种形式的幂律分布的Pareto分布,通常称为80:20规则。)

This phenomenon is useful for caching. If 20% of objects are used 80% of the time and a way can be found to reduce the cost of obtaining that 20%, then the system performance will improve.
(这种现象对于缓存来说是非常有用的。如果20 %的对象被使用的时间占80 %,那么可以找到降低获得的20 %对象成本的方法,这样的话系统性能将得到改善。)

The Long Tail (长尾)

Chris Anderson, of Wired Magazine, coined the term The Long Tail to refer to Ecommerce systems. The idea that a small number of items may make up the bulk of sales, a small number of blogs might get the most hits and so on. While there is a small list of popular items, there is a long tail of less popular ones.
(连线”杂志的(主编)克里斯安德森,提出了涉及电子商务系统的术语长尾。提出了一个思想,少数项目可能弥补大量的销售,也有少数博客可能获得最大的访问等等。虽然是一个小名单中受欢迎的项目,还有不流行的长尾效应。)

Will an Application Benefit from Caching?(应用程序可以从缓存中得益吗?)
The short answer is that it often does, due to the effects noted above.
(简短的回答是,它常常会由于上面提到的影响)

The medium answer is that it often depends on whether it is CPU bound or I/O bound. If an application is I/O bound then the time taken to complete a computation depends principally on the rate at which data can be obtained. If it is CPU bound, then the time taken principally depends on the speed of the CPU and main memory.
(中等答案是,它往往取决于它是否是CPU限制或I / O的约束。如果应用程序是I / O限制,那么用于完成计算的时间主要依赖于获取数据的速度。如果是CPU限制,那么所需要的时间主要取决于CPU的速度和主存储器。)

While the focus for caching is on improving performance, it it also worth realizing that it reduces load. The time it takes something to complete is usually related to the expense of it. So, caching often reduces load on scarce resources.
(然而缓存的主要是用于提高性能,用于减少加载也是比较有意义的。缓存完成一些事情的时间总是跟缓存的代价有关系,缓存常常减少稀缺资源的加载。)

Speeding up CPU bound Applications(加速CPU限制的应用)

CPU bound applications are often sped up by:
(cpu限制的应用从这几个方面进行加速:)

l improving algorithm performance (提高运算法则的性能)
l parallelizing the computations across multiple CPUs (SMP) or multiple machines (Clusters).

并行的计算通过多个CPU的处理( SMP )或多个机器(集群)
l upgrading the CPU speed.(升级CPU的速度)

The role of caching, if there is one, is to temporarily store computations that may be reused again.
(缓存的任务,如果有的话,是暂时存放可再次重复使用计算结果。)

An example from ehcache would be large web pages that have a high rendering cost.
(一个来自ehcache的例子,大量的WEB页面需要昂贵的开销。)

Another caching of authentication status, where authentication requires cryptographic transforms.
(一个缓存的认证状态,加密在身份验证要求变换。)

Speeding up I/O bound Applications
(加快的I/O应用)
Many applications are I/O bound, either by disk or network operations. In the case of databases they can be limited by both.There is no Moore's law for hard disks. A 10,000 RPM disk was fast 10 years ago and is still fast. Hard disks are speeding up by using their own caching of blocks into memory.
(许多应用都受磁盘或网络操作I/O的限制,如果数据库受这两方面的限制,对于硬盘来说没有摩尔规律。 10,000 RPM的硬盘很快了在10年前,目前仍很快。硬盘通过将本身的缓存块放到内存中可以提高其速度。)

Network operations can be bound by a number of factors:
l time to set up and tear down connections
l latency, or the minimum round trip time
l throughput limits
l marshalling and unmarhshalling overhead
(网络操作可以受以下因素的限制:
l 建立和销毁连接的时间
l 延迟或最低往返时间
l 流量限制
l 编组和unmarhshalling开销)

The caching of data can often help a lot with I/O bound applications.
Some examples of ehcache uses are:
l Data Access Object caching for Hibernate
l Web page caching, for pages generated from databases.
(数据缓存对于I/O限制的应用帮助比较大
l Hibernate数据存储对象缓存
l 网页缓存,缓存从数据库生成的网页)

Increased Application Scalability
The flip side of increased performance is increased scalability. Say you have a database which can do 100 expensive queries per second. After that it backs up and if connections are added to it it slowly dies.
(增加可扩展性的应用
另一方面在提高了性能时,提高可扩展性。假如你有一个数据库,它可以做每秒100次昂贵查询。然后一直支持,如果连接被接入它就会慢慢死去。)

In this case, caching may be able to reduce the workload required. If caching can cause 90 of that 100 to be cache hits and not even get to the database, then the database can scale 10 times higher than otherwise.
(在这种情况下,缓存可以减少所需的工作量,如果缓存的90%被访问,并不需要从数据库中获取。那么数据库可以规模可以是其它的10倍以上。)

How much will an application speed up with Caching?
The short answer
The short answer is that it depends on a multitude of factors being:
(使用缓存的应用程序可以提高速度多少?
简单的答案
简单的答案是它依赖很多的因素:


l how many times a cached piece of data can and is reused by the application
l the proportion of the response time that is alleviated by caching
l In applications that are I/O bound, which is most business applications, most of the response time is getting data from a database. Therefore the speed up mostly depends on how much reuse a piece of data gets.

l 一个数据的缓存块被应用程序重复使用次数。
l 通过缓存减少反应时间的比列
l 在I/O限制的应用程序中,最主要在商业系统中,更过的响应时间是从数据库获取数据,因此提高主要依赖于重用数据块的多少。


In a system where each piece of data is used just once, it is zero. In a system where data is reused a lot, the speed up is large.
The long answer, unfortunately, is complicated and mathematical. It is considered next.
(在一个系统,每一块的数据是只使用一次,它是零。系统中数据是大量的重复使用那么提高比较快。
最终的答案,不幸的它是复杂性和数学。接下来将考虑它)

Applying Amdahl's Law
Amdahl's law, after Gene Amdahl, is used to find the system speed up from a speed up in part of the system.
(应用阿姆达尔定律
阿姆达尔定律,基因阿姆达尔,是从系统中一部分速度的提高来发现系统速度的提高,)

1 / ((1 - Proportion Sped Up) + Proportion Sped Up / Speed up)The following examples show how
to apply Amdahl's law to common situations. In the interests of simplicity, we assume:
(1 / ( ( 1 -比例加速) +比例加速/加速)下面的例子显示如何将阿姆达尔定律应用到普通的情形。简单的影响,我们假定


l a single server
l a system with a single thing in it, which when cached, gets 100% cache hits and lives forever.
(单一的服务器
系统中只有单一的事件,当系统被缓存,缓存100%被访问并且永远存活。)

Persistent Object Relational Caching
A Hibernate Session.load() for a single object is about 1000 times faster from cache than from a database.
(持久对象关联缓存
使用Hibernate的Session.load ( )方法从一个缓存中获取一个简单对象的速度比从数据库中获取快1000倍。)

A typical Hibernate query will return a list of IDs from the database, and then attempt to load each. If Session.iterate() is used Hibernate goes back to the database to load each object.
(一个典型的Hibernate的查询将从数据库中返回一个列表的ID,然后尝试加载每个。如果Session.iterate ( )方法被调用,那么Hibernate将返回数据加载每一个对象。)

Imagine a scenario where we execute a query against the database which returns a hundred IDs and then load each one.
(象一个场景,我们执行查询的数据库,它返回一个100的ID 并且加载每一个。)

The query takes 20% of the time and the roundtrip loading takes the rest (80%). The database query itself is 75% of the time that the operation takes. The proportion being sped up is thus 60% (75% * 80%).
(一个查询需要20 %的时间,来回的加载需要剩余的时间( 80 % ) 。该数据库本身查询需要整个操作时间的75 %。所以速度提高的比例是60%( 75 % * 80 %)。)

The expected system speedup is thus:
1 / ((1 - .6) + .6 / 1000)
= 1 / (.4 + .006)
= 2.5 times system speedup
(统加速的预期,因此:
1 / ( ( 1 - 0.6 ) + 0.6 / 1000 )
= 1 / ( 0.4 + 0.006 )
= 2.5倍系统加速。)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: