| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <title>Pegasus | Background</title> |
| <link rel="stylesheet" href="/zh/assets/css/app.css"> |
| <link rel="shortcut icon" href="/zh/assets/images/favicon.ico"> |
| <link rel="stylesheet" href="/zh/assets/css/utilities.min.css"> |
| <link rel="stylesheet" href="/zh/assets/css/docsearch.v3.css"> |
| <script src="/assets/js/jquery.min.js"></script> |
| <script src="/assets/js/all.min.js"></script> |
| <script src="/assets/js/docsearch.v3.js"></script> |
| <!-- Begin Jekyll SEO tag v2.8.0 --> |
| <title>Background | Pegasus</title> |
| <meta name="generator" content="Jekyll v4.3.3" /> |
| <meta property="og:title" content="Background" /> |
| <meta property="og:locale" content="en_US" /> |
| <meta name="description" content="设计目标" /> |
| <meta property="og:description" content="设计目标" /> |
| <meta property="og:site_name" content="Pegasus" /> |
| <meta property="og:type" content="article" /> |
| <meta property="article:published_time" content="2024-04-22T06:39:52+00:00" /> |
| <meta name="twitter:card" content="summary" /> |
| <meta property="twitter:title" content="Background" /> |
| <script type="application/ld+json"> |
| {"@context":"https://schema.org","@type":"BlogPosting","dateModified":"2024-04-22T06:39:52+00:00","datePublished":"2024-04-22T06:39:52+00:00","description":"设计目标","headline":"Background","mainEntityOfPage":{"@type":"WebPage","@id":"/overview/background/"},"url":"/overview/background/"}</script> |
| <!-- End Jekyll SEO tag --> |
| </head> |
| |
| <body> |
| |
| |
| |
| |
| <nav class="navbar is-primary"> |
| <div class="container"> |
| <!--container will be unwrapped when it's in docs--> |
| <div class="navbar-brand"> |
| <a href="/zh/" class="navbar-item "> |
| <!-- Pegasus Icon --> |
| <img src="/assets/images/pegasus.svg"> |
| </a> |
| <div class="navbar-item"> |
| <a href="/zh/docs" class="button is-primary is-outlined is-inverted"> |
| <span class="icon"><i class="fas fa-book"></i></span> |
| <span>Docs</span> |
| </a> |
| </div> |
| <div class="navbar-item is-hidden-desktop"> |
| |
| |
| <!--A simple language switch button that only supports zh and en.--> |
| <!--IF its language is zh, then switches to en.--> |
| |
| <!--If you don't want a url to be relativized, you can add a space explicitly into the href to |
| prevents a url from being relativized by polyglot.--> |
| <a class="button is-primary is-outlined is-inverted" href=" /overview/background/"><strong>En</strong></a> |
| |
| </div> |
| <a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navMenu"> |
| <!-- Appears in mobile mode only --> |
| <span aria-hidden="true"></span> |
| <span aria-hidden="true"></span> |
| <span aria-hidden="true"></span> |
| </a> |
| </div> |
| <div class="navbar-menu" id="navMenu"> |
| <div class="navbar-end"> |
| |
| <!--dropdown--> |
| <div class="navbar-item has-dropdown is-hoverable "> |
| <a href="" |
| class="navbar-link "> |
| |
| <span class="icon" style="margin-right: .25em"> |
| <i class="fas fa-users"></i> |
| </span> |
| |
| <span> |
| ASF |
| </span> |
| </a> |
| <div class="navbar-dropdown"> |
| |
| <a href="https://www.apache.org/" |
| class="navbar-item "> |
| Foundation |
| </a> |
| |
| <a href="https://www.apache.org/licenses/" |
| class="navbar-item "> |
| License |
| </a> |
| |
| <a href="https://www.apache.org/events/current-event.html" |
| class="navbar-item "> |
| Events |
| </a> |
| |
| <a href="https://www.apache.org/foundation/sponsorship.html" |
| class="navbar-item "> |
| Sponsorship |
| </a> |
| |
| <a href="https://www.apache.org/security/" |
| class="navbar-item "> |
| Security |
| </a> |
| |
| <a href="https://privacy.apache.org/policies/privacy-policy-public.html" |
| class="navbar-item "> |
| Privacy |
| </a> |
| |
| <a href="https://www.apache.org/foundation/thanks.html" |
| class="navbar-item "> |
| Thanks |
| </a> |
| |
| </div> |
| </div> |
| |
| |
| <!--dropdown--> |
| <div class="navbar-item has-dropdown is-hoverable "> |
| <a href="/zh/community" |
| class="navbar-link "> |
| |
| <span class="icon" style="margin-right: .25em"> |
| <i class="fas fa-user-plus"></i> |
| </span> |
| |
| <span> |
| 开源社区 |
| </span> |
| </a> |
| <div class="navbar-dropdown"> |
| |
| <a href="/zh/community/#contact-us" |
| class="navbar-item "> |
| 联系我们 |
| </a> |
| |
| <a href="/zh/community/#contribution" |
| class="navbar-item "> |
| 参与贡献 |
| </a> |
| |
| <a href="https://cwiki.apache.org/confluence/display/PEGASUS/Coding+guides" |
| class="navbar-item "> |
| 编码指引 |
| </a> |
| |
| <a href="https://github.com/apache/incubator-pegasus/issues?q=is%3Aissue+is%3Aopen+label%3Atype%2Fbug" |
| class="navbar-item "> |
| Bug 追踪 |
| </a> |
| |
| <a href="https://cwiki.apache.org/confluence/display/INCUBATOR/PegasusProposal" |
| class="navbar-item "> |
| Apache 提案 |
| </a> |
| |
| </div> |
| </div> |
| |
| |
| |
| <a href="/zh/blogs" |
| class="navbar-item "> |
| |
| <span class="icon" style="margin-right: .25em"> |
| <i class="fas fa-rss"></i> |
| </span> |
| |
| <span>Blog</span> |
| </a> |
| |
| |
| |
| <a href="/zh/docs/downloads" |
| class="navbar-item "> |
| |
| <span class="icon" style="margin-right: .25em"> |
| <i class="fas fa-fire"></i> |
| </span> |
| |
| <span>版本发布</span> |
| </a> |
| |
| |
| </div> |
| <div class="navbar-item is-hidden-mobile"> |
| |
| |
| <!--A simple language switch button that only supports zh and en.--> |
| <!--IF its language is zh, then switches to en.--> |
| |
| <!--If you don't want a url to be relativized, you can add a space explicitly into the href to |
| prevents a url from being relativized by polyglot.--> |
| <a class="button is-primary is-outlined is-inverted" href=" /overview/background/"><strong>En</strong></a> |
| |
| </div> |
| </div> |
| </div> |
| </nav> |
| |
| <section class="section"> |
| <div class="container"> |
| <div class="columns is-multiline"> |
| <div class="column is-one-fourth"> |
| |
| |
| |
| <aside class="menu"> |
| |
| <p class="menu-label"></p> |
| <ul class="menu-list"> |
| |
| <li> |
| <a href="/zh/overview" |
| class=""> |
| 概览 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/overview/background" |
| class=""> |
| 项目背景 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/overview/architecture" |
| class=""> |
| 系统架构 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/overview/data-model" |
| class=""> |
| 数据模型 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/overview/benchmark" |
| class=""> |
| 性能测试 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/docs/build/compile-by-docker" |
| class=""> |
| 安装构建 |
| </a> |
| </li> |
| |
| <li> |
| <a href="/zh/overview/onebox" |
| class=""> |
| 体验 Onebox 集群 |
| </a> |
| </li> |
| |
| </ul> |
| |
| </aside> |
| |
| </div> |
| <div class="column is-half"> |
| |
| |
| |
| <div class="content"> |
| <h1 id="项目背景">项目背景</h1> |
| <h1 id="设计目标">设计目标</h1> |
| |
| <ul> |
| <li>高可用:系统必须是高可用的。即使部分服务器宕机,Pegasus集群也能在极短时间(秒级)内恢复服务,尽量减少对用户的影响,要求服务可靠性达到99.99%以上。</li> |
| <li>高性能:系统能够提供高性能的读写服务,P99延迟需要在毫秒级别。</li> |
| <li>强一致:系统对用户提供强一致性的语义,使用户在编写业务逻辑时更容易。</li> |
| <li>易伸缩:系统能够很方便地扩容和缩容,以应对业务吞吐负载的变化。</li> |
| <li>易使用:系统给用户提供简单易用的库和接口,方便用户使用。</li> |
| </ul> |
| |
| <h1 id="实现方案">实现方案</h1> |
| |
| <p>在设计Pegasus时,我们在目标、实现难度、开发效率等方面做一些权衡。总的来说,包括这几个方面:</p> |
| <ul> |
| <li>开发语言:基于性能考虑,我们选择了C++。</li> |
| <li>数据模型:采用简单的Key-Value数据模型。这既简化了开发,也能满足大部分业务需求。进一步地,我们将Key拆分为了HashKey和SortKey两级,加强了其表达能力。</li> |
| <li>数据分布:采用固定Hash分布。相比Range分布和一致性Hash分布,固定Hash分布实现更简单,数据倾斜和可伸缩性可以通过合理设计Hash键、预设更多的数据分片等措施来解决。我们也支持<a href="https://pegasus.apache.org/zh/administration/partition-split">Partition Split</a>功能来扩展分片数量。</li> |
| <li>存储介质:建议选择SSD(固态硬盘)。SSD的性能和成本都介于内存和HDD(机械硬盘)之间,从业务需求和成本综合考虑,选择SSD是比较合适的。</li> |
| <li>本地存储引擎:选择<a href="https://github.com/facebook/rocksdb">RocksDB</a>。RocksDB在LevelDB基础上做了很多优化,能充分利用SSD的IOPS性能和多核服务器的计算性能。</li> |
| <li>一致性协议:选择<a href="https://www.microsoft.com/en-us/research/publication/pacifica-replication-in-log-based-distributed-storage-systems/">PacificA</a>。相比<a href="https://raft.github.io/">Raft</a>,PacificA协议具有其自身的特点和优势。</li> |
| <li>故障检测:和HBase不同,Pegasus没有使用Zookeeper来进行故障检测,而是在MetaServer和ReplicaServer之间实现了基于租约的故障检测机制。</li> |
| </ul> |
| |
| <h1 id="与hbase比较">与HBase比较</h1> |
| |
| <p>Pegasus系统的最初目的就是弥补HBase的不足,这里从用户使用角度比较一下两者的区别:</p> |
| <ul> |
| <li>数据模型:HBase是表格模型,采用Range分片;Pegasus是Key-Value模型,采用Hash分片。</li> |
| <li>接口:HBase的API接口功能虽然很丰富,但是使用也更复杂;Pegasus的接口简单,对用户更友好。</li> |
| <li>可靠性:由于架构和实现的原因(如Pegasus采用的本地存储、故障检测、使用C++语言实现等),Pegasus的可靠性通常优于HBase。</li> |
| <li>性能:由于分层架构,HBase的读写性能不是太好,P99延迟通常在几十甚至几百毫秒,而且GC问题会带来毛刺问题;Pegasus的P99可以在几毫秒,满足敏感在线业务的需求。</li> |
| </ul> |
| |
| <h1 id="与redis比较">与Redis比较</h1> |
| |
| <p>如果仅从读写延迟和单机吞吐比较,Redis显然是优于Pegasus的。但如果从读写延迟、可用性、伸缩性、成本等方面综合比较,Pegasus也是有其自身的优势的。</p> |
| |
| <p>与Redis进行比较的主要区别如下:</p> |
| <ul> |
| <li>数据模型:两者都是Key-Value模型,但是Pegasus支持(HashKey + SortKey)的二级键。</li> |
| <li>接口:Redis的接口更丰富,支持List、Set、Map等容器特性;Pegasus的接口相对简单,功能更单一。</li> |
| <li>读写延迟:Redis性能比Pegasus好。</li> |
| <li>伸缩性:Pegasus伸缩性更好,可以很方便地增减机器节点,并支持自动的负载均衡;Redis的分布式方案在增减机器的时候比较麻烦。</li> |
| <li>可靠性:Pegasus数据总是持久化的,系统架构保证其较高的数据完整性;Redis在机器宕机后需要较长时间恢复,可用性不够好,还可能丢掉最后一段时间的数据。</li> |
| <li>成本:Pegasus使用SSD存储全量数据,而Redis需要使用内存来存储全量数据,Pegasus成本更低。</li> |
| </ul> |
| |
| <h1 id="综合比较">综合比较</h1> |
| |
| <p>业务在系统选型时,通常遇到这些问题:</p> |
| <ul> |
| <li>HBase虽然可用性高也易伸缩,但是性能不够好。</li> |
| <li>Redis虽然性能好,但是需要大量内存,带来更昂贵的硬件成本。如果数据量太大,采用<a href="https://redis.io/topics/cluster-tutorial">Redis Cluster</a>方案,在机器宕机故障情况下的可用性又不够。</li> |
| <li>HBase+Redis的方案,即使用HBase做底层存储,使用Redis做上层缓存。该方案的缺点是:涉及两个系统,用户的读写逻辑会比较复杂;同时写两个系统,容易出现一致性问题;一份数据要同时存储在HBase和Redis中,成本比较高;Redis机器宕机后造成部分缓存丢失,此时从HBase读取的性能又明显降低。</li> |
| </ul> |
| |
| <p>Pegasus综合了HBase和Redis的优点,它既保证高的可靠性,又具有好的伸缩性,还具有良好的性能。</p> |
| |
| </div> |
| </div> |
| <div class="column is-one-fourth is-hidden-mobile" style="padding-left: 3rem"> |
| |
| <p class="menu-label"> |
| <span class="icon"> |
| <i class="fa fa-bars" aria-hidden="true"></i> |
| </span> |
| 本页导航 |
| </p> |
| <ul class="menu-list"> |
| <li><a href="#项目背景">项目背景</a></li> |
| <li><a href="#设计目标">设计目标</a></li> |
| <li><a href="#实现方案">实现方案</a></li> |
| <li><a href="#与hbase比较">与HBase比较</a></li> |
| <li><a href="#与redis比较">与Redis比较</a></li> |
| <li><a href="#综合比较">综合比较</a></li> |
| </ul> |
| |
| |
| </div> |
| </div> |
| </div> |
| </section> |
| <footer class="footer"> |
| <div class="container"> |
| <div class="content is-small has-text-centered"> |
| <div style="margin-bottom: 20px;"> |
| <a href="http://incubator.apache.org"> |
| <img src="/assets/images/egg-logo.png" |
| width="15%" |
| alt="Apache Incubator"/> |
| </a> |
| </div> |
| Copyright © 2023 <a href="http://www.apache.org">The Apache Software Foundation</a>. |
| Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version |
| 2.0</a>. |
| <br><br> |
| |
| Apache Pegasus is an effort undergoing incubation at The Apache Software Foundation (ASF), |
| sponsored by the Apache Incubator. Incubation is required of all newly accepted projects |
| until a further review indicates that the infrastructure, communications, and decision making process |
| have stabilized in a manner consistent with other successful ASF projects. While incubation status is |
| not necessarily a reflection of the completeness or stability of the code, it does indicate that the |
| project has yet to be fully endorsed by the ASF. |
| |
| <br><br> |
| Apache Pegasus, Pegasus, Apache, the Apache feather logo, and the Apache Pegasus project logo are either |
| registered trademarks or trademarks of The Apache Software Foundation in the United States and other |
| countries. |
| </div> |
| </div> |
| </footer> |
| <script src="/assets/js/app.js" type="text/javascript"></script> |
| </body> |
| </html> |