Home Database Mysql Tutorial 润乾集算报表提升性能之可控缓存

润乾集算报表提升性能之可控缓存

Jun 07, 2016 pm 04:12 PM
use Can performance Report promote cache

使用缓存可以提升报表性能是不争的事实,一般高端报表工具都会提供报表缓存的功能,用于将整个报表计算结果缓存到文件系统中,以便用户在下次访问同参数报表时可以快速读取缓存结果进行报表展现,集算报表也具有这种常规缓存功能。但是,有些情况下报表开发

使用缓存可以提升报表性能是不争的事实,一般高端报表工具都会提供报表缓存的功能,用于将整个报表计算结果缓存到文件系统中,以便用户在下次访问同参数报表时可以快速读取缓存结果进行报表展现,集算报表也具有这种常规缓存功能。但是,有些情况下报表开发人员希望能够控制缓存的内容,比如有时希望缓存的不是整个报表结果而是其中的部分,有时缓存内容可被其它报表或程序复用,有时希望对不同的缓存结果设置不同的超时时间,以应对数据量和实时性方面的不同情况。这时,一般的报表缓存就无法满足需求了。

集算报表内置了可编程的数据计算引擎,允许开发人员灵活控制缓存内容。这里我们将开发人员在使用集算报表开发中可以控制的缓存内容称为可控缓存。可按缓存可以带来更大的灵活性和好处,下面就前述提到的三点展开来说。

缓存部分结果

在报表开发中,有时并不希望将所有报表结果进行缓存,这样可以避免耗费过高的缓存成本(磁盘空间和应用服务器资源开销)。另外,当报表中的部分数据实时性要求很高,需要实时与数据库交互进行数据查询,那么这部分数据就不适合进行缓存,这时通过集算报表的可控缓存就可以将变化不太频繁的中间结果缓存起来。报表再次请求时,实时性要求高的数据仍然实时从数据库中读取,并结合缓存中的数据进行报表计算,得到最终报表结果集。常规缓存方案没有这种缓存部分结果的功能,只能设置整个报表是否进行缓存,这样在报表涉及各部分数据的时效性不同时就会发生矛盾;而集算报表在这方面更加灵活,效率更高。

 

缓存结果复用

集算报表中可控缓存是可以复用的,一个报表的缓存结果(部分或全部)可以被其他报表或程序读取并使用,而不必再次缓存同样的结果(常规报表缓存方案则会重复),这会大幅度提供整体缓存的效率。与缓存部分结果适应实时性要求的情况类似,当其他报表或程序使用某个报表的缓存结果时,只需要从缓存中(一般是磁盘文件)读取,并与报表中其他数据来源(可能是DB、文件,或是另一个报表的缓存)进行混合运算最终得到报表结果集。常规的报表缓存则是以报表模板为单位单立的,彼此无法复用,会造成一定的资源浪费以及增加一定的性能开销,而集算报表在这方面更加灵活,效率更高。

 

设置不同超时时间

我们都熟知的缓存一定会有超时时间,超时时间外缓存会被清除,报表访问时重新生成缓存文件。一般的报表工具的缓存超时时间会在配置文件中设置,如3600s或7200s,这种设置对应用中的报表在所有参数情况甚至所有的报表均有效,换句话说,整个报表甚至整个系统必须使用同样的设置。

然而,事实并不希望这样,如果能够针对不同的报表场景设置不同的超时时间,那样会更有效。比如,针对大量的历史数据查询的报表,由于历史数据的变化不大,我们希望报表的缓存结果可以保存较长时间,以便每次查询时都能从缓存中快速读取结果,这时需要设置较长的超时时间;而针对数据变化频繁,实时性要求较高的报表则超时时间会较短,以便满足数据的实时性要求。

集算报表的结果缓存允许开发人员针对不同的报表设置不同的超时时间,以应对上述提到的报表场景。同样,这种做法提供了更高的灵活性,使得报表缓存达到真正意义上的人为可控。

 

举例

具体实现上可以参考集算报表的相关文档资料,这里通过一个例子简单说明结果缓存的使用方法,可以参考如下步骤(举例说明):

1、使用集算报表内置的集算器编写脚本生成/读取缓存文件,这个过程处于报表数据源的计算阶段。

\

 

上述脚本首先指定缓存目录,并根据参数设置缓存文件名称,并根据文件名查找缓存文件是否存在(A4),若存在并且未超时则直接读缓存;否则,进行连接数据库取数运算,并将计算结果生成缓存文件。

 

如果报表中不使用缓存,那么脚本只需要这样编写:

\

2、在集算报表中调用上述集算脚本,编辑报表表达式完成报表制作。

 

需要注意的是,集算报表的可控缓存也有其适用场景,并不能完全取代常规缓存,常规缓存手段会连同报表计算结果以及呈现属性一起,而这里的可控缓存只缓存数据,在呈现时还要再次进行外观计算,更适用于数据计算强度较高,但外观计算强度较低的场景。实际应用中,两者可以结合使用。


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1667
14
PHP Tutorial
1273
29
C# Tutorial
1255
24
BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

PHP array key value flipping: Comparative performance analysis of different methods PHP array key value flipping: Comparative performance analysis of different methods May 03, 2024 pm 09:03 PM

The performance comparison of PHP array key value flipping methods shows that the array_flip() function performs better than the for loop in large arrays (more than 1 million elements) and takes less time. The for loop method of manually flipping key values ​​takes a relatively long time.

Performance comparison of different Java frameworks Performance comparison of different Java frameworks Jun 05, 2024 pm 07:14 PM

Performance comparison of different Java frameworks: REST API request processing: Vert.x is the best, with a request rate of 2 times SpringBoot and 3 times Dropwizard. Database query: SpringBoot's HibernateORM is better than Vert.x and Dropwizard's ORM. Caching operations: Vert.x's Hazelcast client is superior to SpringBoot and Dropwizard's caching mechanisms. Suitable framework: Choose according to application requirements. Vert.x is suitable for high-performance web services, SpringBoot is suitable for data-intensive applications, and Dropwizard is suitable for microservice architecture.

How to optimize the performance of multi-threaded programs in C++? How to optimize the performance of multi-threaded programs in C++? Jun 05, 2024 pm 02:04 PM

Effective techniques for optimizing C++ multi-threaded performance include limiting the number of threads to avoid resource contention. Use lightweight mutex locks to reduce contention. Optimize the scope of the lock and minimize the waiting time. Use lock-free data structures to improve concurrency. Avoid busy waiting and notify threads of resource availability through events.

How to use caching in Golang distributed system? How to use caching in Golang distributed system? Jun 01, 2024 pm 09:27 PM

In the Go distributed system, caching can be implemented using the groupcache package. This package provides a general caching interface and supports multiple caching strategies, such as LRU, LFU, ARC and FIFO. Leveraging groupcache can significantly improve application performance, reduce backend load, and enhance system reliability. The specific implementation method is as follows: Import the necessary packages, set the cache pool size, define the cache pool, set the cache expiration time, set the number of concurrent value requests, and process the value request results.

What is Bitget Launchpool? How to use Bitget Launchpool? What is Bitget Launchpool? How to use Bitget Launchpool? Jun 07, 2024 pm 12:06 PM

BitgetLaunchpool is a dynamic platform designed for all cryptocurrency enthusiasts. BitgetLaunchpool stands out with its unique offering. Here, you can stake your tokens to unlock more rewards, including airdrops, high returns, and a generous prize pool exclusive to early participants. What is BitgetLaunchpool? BitgetLaunchpool is a cryptocurrency platform where tokens can be staked and earned with user-friendly terms and conditions. By investing BGB or other tokens in Launchpool, users have the opportunity to receive free airdrops, earnings and participate in generous bonus pools. The income from pledged assets is calculated within T+1 hours, and the rewards are based on

Caching mechanism and application practice in PHP development Caching mechanism and application practice in PHP development May 09, 2024 pm 01:30 PM

In PHP development, the caching mechanism improves performance by temporarily storing frequently accessed data in memory or disk, thereby reducing the number of database accesses. Cache types mainly include memory, file and database cache. Caching can be implemented in PHP using built-in functions or third-party libraries, such as cache_get() and Memcache. Common practical applications include caching database query results to optimize query performance and caching page output to speed up rendering. The caching mechanism effectively improves website response speed, enhances user experience and reduces server load.

What is the performance impact of converting PHP arrays to objects? What is the performance impact of converting PHP arrays to objects? Apr 30, 2024 am 08:39 AM

In PHP, the conversion of arrays to objects will have an impact on performance, mainly affected by factors such as array size, complexity, object class, etc. To optimize performance, consider using custom iterators, avoiding unnecessary conversions, batch converting arrays, and other techniques.

See all articles