search
HomeDatabaseMysql Tutorial分布式缓存能否作为NoSQL数据库?

对于文档、对象图、键值对这样的非关系型数据类型,NoSQL数据库为它们提供了另一种可选的数据存储方式。分布式缓存能被用作NoSQL数据库吗?Ehcache的Greg Luck

对于文档、对象图、键值对这样的非关系型数据类型,NoSQL数据库为它们提供了另一种可选的数据存储方式。分布式缓存能被用作NoSQL数据库吗?Ehcache的Greg Luck撰文描述了分布式缓存与NoSQL数据库的相似性。InfoQ就此采访了他,讨论了该方案的利弊之处。

InfoQ:你能否就分布式缓存解决方案与NoSQL数据库做个对比?

Greg Luck:分布式缓存通常会把数据放在内存里,用于降低延时。NoSQL数据库是没有R的DBMS(即没有关系的数据库管理系统),一般也缺乏对事务和其他高级特性的支持。对于不支持关系的系统,表关系的关联是SQL里最麻烦的部分,这也正是NoSQL这个名字的起源。

其中一种NoSQL数据库是键值存储。典型的例子包括Dynamo、Oracle NoSQL Database和Redis。缓存也是键值存储,因此说这两者是相关的。很多缓存实现能被配置为可持久化的,之所以很多时候不那么做,是因为缓存是要提升性能而不是做持久化。而NoSQL数据库则与此相反,它是用来做持久化的。

持久化缓存也可当作键值NoSQL数据库来使用。NoSQL也提到了Big Data,通常是指比能放进一个单独的RDBMS节点的量要大的数据,一般从几TB到几PB。

分布式缓存通常用于降低事务性数据的延时,这些数据开始时并不大,但慢慢就会往Big Data这个方向发展。由于缓存将数据保存在内存里,这提高了存储的成本,而且需要限制数据的大小。如果依赖于堆存储,每个服务器节点可能只有可怜的2GB。如果依赖于分布式缓存,Ehcache还提供了堆外存储,每台服务器可以存储几百GB数据,可以用作TB级别的缓存。

持久化、分布式的缓存可以适用于一些NoSQL的场景。NoSQL数据库也可以应对一些缓存的场景,只是延时稍高而已。

InfoQ:从架构角度来看,分布式缓存和NoSQL数据库有什么相似之处吗?

Greg:它们都想提供优于RDBMS的TPS和可扩展性。为此,它们都在功能上做了简化,抛开了那些麻烦的问题,比如表关联、存储过程和ACID事务。

虽然Java缓存领域里有JSR 107,它为Spring和Java EE程序员提供了一套标准的缓存API,但是比起标准化接口,它们都更倾向于使用私有接口。

它们都采用对客户端透明的方式对数据进行分区,做向外扩展。非Java产品向上扩展做得也很好。拥有Terracotta BigMemory,我们在Java平台上的向上扩展方面也做得很特别。最后,两者都可以部署在常见的硬件和操作系统上,这让它们都能理想地运行于云端。

InfoQ:架构上这两项技术又有何不同呢?

Greg:NoSQL和RDBMS通常使用的是磁盘。磁盘是机械设备,延时很厉害,因为寻道时间是磁头移动到正确的磁道的时间,读写时间依赖于磁盘的RPM。NoSQL尝试优化磁盘的使用,例如,仅仅在磁头当前位置追加日志,偶尔才刷新到磁盘上。相反,缓存主要都把数据放内存里。

NoSQL和RDBMS的客户端很薄(想想Thrift或JDBC),只是在网络中传输数据,而像Ehcache这样的缓存使用进程内存储和远程存储,因此常用请求在本地就能被成功处理。在分布式缓存上下文中,每个应用程序服务器的进程内存储中都会缓存热点数据,增加服务器数量并不会增加网络或后端的负载。

RDBMS专注于成为通用的SOR(System of Record)。NoSQ希望成为某类特定数据类型的SOR,比如键值对、文档、稀疏表(宽表)或图。缓存着眼于性能,一般会与RDBMS或NoSQL数据库结合使用,数据类型就是SOR。往往缓存中会存储Web服务调用的结果,业务对象的计算结果,这个结果可能需要成百SOR调用才能得到。

像Ehcache这样的缓存部分运行在应用程序的操作系统进程里,部分运行在网络那头自己机器的进程里。但也不是全部分布式缓存都这样:memcache就是一个例子,所有的数据都跨网络存储。

InfoQ:哪类应用程序最适合这种方式?

Greg:这还得从先前的问题说起,要将分布式缓存用于你现有的应用程序,通常只需要很小的工作量,而NoSQL则需要做很多事,还有大的架构变更。

因此适用分布式缓存的第一类应用程序是现有系统,特别是有以下需要的:

由于使用量或负载激增而需要向外扩展

为达到SLA而需要有更低的延时

为了将大型机这样的昂贵基础设施的使用减到最低

减少Web服务调用而带来的费用

应对极端负载高峰(比如黑色星期五一样的促销)

InfoQ:这种方式有什么局限么?

Greg:缓存,置于内存之中,在大小上有制约,它们的技术局限受限于有多少内存给它们使用(下面还会具体展开说明)。

缓存,就算它提供持久化功能,也未必算的上作为SOR的上选。缓存故意回避了备份到磁盘和从中还原的复杂功能,尽管也有简单的。RDMBS在过去30年里开发了丰富的备份、还原、迁移、报表和ETL特性。而NoSQL则介于两者之间。

缓存提供了改变数据与访问数据的编程API。NoSQL和RDBMS则提供了工具,可以执行脚本化语言(比如SQL、UnSQL和Thrift)。

但关键一点是要记住缓存并不想成为你的SOR。它能轻松地与你的RDBMS和睦相处,为此它并不需要RDBMS所有用的复杂功能。

InfoQ:以后分布式缓存解决方案、NoSQL数据库和传统RDBMS互相协同工作,你有何看法?

Greg:速度大幅快于RDBMS,依赖于部署拓扑的NoSQL,还有数据访问模式,分布式缓存可以位于这三者之间的任意位置。那些需要更低延时的人可以将缓存作为NoSQL的一个补充,就像现在对待RDBMS那样。

稍有不同的是,在你想将RDBMS扩展到多个节点时,经常会难于扩展,或者影响编程契约,或者受制于CAP做出权衡;而使用NoSQL,就算只使用一个节点,你也可以简单地将其视为多节点安装。如果是向上扩展就没有这些问题。在RDBMS中,添加缓存是为了避免向外扩展会遇到的麻烦。通常缓存能解决系统的容量问题,你不用费太多力气。因此当需要向外扩展时,加入缓存吧。

对于NoSQL而言,内建了向外扩展的能力,在需要低延时的时候使用缓存吧。

查看英文原文:Distributed Cache as a NoSQL Data Store?

译者 丁雪丰 是InfoQ中文站编辑,满江红翻译组核心成员,出版过《Spring攻略》、《JRuby实战》等多部译著。主要关注领域:企业级应用、海量数据计算、动态语言应用等。

Statement
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
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

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 Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor