HBase Profiling
By Lars Hofhansl Modern CPU cores can execute hundreds of instructions in the time it takes to reload the L1 cache. "RAM is the new disk" as a coworker at Salesforce likes to say. The L1-cache is the new RAM I might add. As we add more and
By Lars HofhanslModern CPU cores can execute hundreds of instructions in the time it takes to reload the L1 cache. "RAM is the new disk" as a coworker at Salesforce likes to say. The L1-cache is the new RAM I might add.
As we add more and more CPU cores, we can easily be memory IO bound unless we are a careful.
Many common problems I have seen over the years were related to:
-
concurrency problems
Aside from safety and liveliness considerations, a typical problem is too much synchronization limiting potential parallel execution. -
unneeded or unintended memory barriers
Memory barriers are required in Java by the following language constructs:- synchronized - sets read and write barriers as needed (details depend on JVM, version, and settings)
- volatile - sets a read barrier before a read to a volatile, and write barrier after a write
- final - set a write barrier after the assignment
- AtomicInteger, AtomicLong, etc - uses volatiles and hardware CAS instructions
-
unnecessary, unintended, or repeated memory copy or access
Memory copying is often seen in Java for example because of the lack of in-array pointers, or really just general unawareness and the expectation that "garbage collector will clean up the mess." Well, it does, but not without a price.
Like any software project of reasonable size, HBase has problems of all the above categories.
Profiling in Java has become extremely convenient. Just start jVisualVM which ships with the
Over the past few weeks I did some on and off profiling in HBase, which lead to the following issues:
HBASE-6603 - RegionMetricsStorage.incrNumericMetric is called too often
Ironically here it was the collection of a performance metric that caused a measurable slowdown of up 15%(!) for very wide rows (> 10k columns).The metric was maintained as an AtomicLong, which introduced a memory barrier in one of the hottest code paths in HBase.
The good folks at Facebook have found the same issue at roughly the same time. (It turns that they were also... uhm... the folks who introduced the problem.)
HBASE-6621 - Reduce calls to Bytes.toInt
A KeyValue (the data structure that represents "columns" in HBase) is currently backed by a single byte[]. The sizes of the various parts are encoded in this byte[] and have to read and decoded; each time an extra memory access. In many cases that can be avoided, leading to slight performance improvement.HBASE-6711 - Avoid local results copy in StoreScanner
All references pertaining to a single row (i.e. KeyValue with the same row key) were copied at the StoreScanner layer. Removing this lead to another slight performance increase with wide rows.HBASE-7180 - RegionScannerImpl.next() is inefficient
This introduces a mechanism for coprocessors to access RegionScanners at a lower level, thus allowing skipping of a lot of unnecessary setup for each next() call. In tight loops a coprocessor can make use of this new API to save another 10-15%.HBASE-7279 - Avoid copying the rowkey in RegionScanner, StoreScanner, and ScanQueryMatcher
The row key of KeyValue was copied in the various scan related classes. To reduce that effect the row key was previously cached in the KeyValue class - leading to extra memory required for each KeyValue.This change avoids all copying and hence also obviates the need for caching the row key.
A KeyValue now is hardly more than an array pointer (a byte[], an offset, and a length), and no data is copied any longer all the way from the block loaded from disk or cache to the RPC layer (unless the KeyValues are optionally encoded on disk, in which case they still need to be decoded in memory - we're working on improving that too).
Previously the size of a KeyValue on the scan path was at least 116 bytes + the length of the rowkey (which can be arbitrarily long). Now it is ~60 bytes, flat and including its own reference.
(remember during a course of a large scan we might be creating millions or even billions of KeyValue objects)
This is nice improvement both in term of scan performance (15-20% for small row keys of few bytes, much more for large ones) and in terms of produced garbage.
Since all copying is avoided, scanning now scales almost linearly with the number of cores.
HBASE-6852 - SchemaMetrics.updateOnCacheHit costs too much while full scanning a table with all of its fields
Other folks have been busy too. Here Cheng Hao found another problem with a scan related metric that caused a noticeable slowdown (even though I did not believe him first).This removed another set of unnecessary memory barriers.
HBASE-7336 - HFileBlock.readAtOffset does not work well with multiple threads
This is slightly different issue caused by bad synchronization of the FSReader associated with a Storefile. There is only a single reader per storefile. So if the file's blocks are not cached - possibly because the scan indicated that it wants no caching, because it expects to touch too many blocks - the scanner threads are now competing for read access to the store file. That lead to outright terrible performance, such a scanners timing out even with just two scanners accessing the same file in tight loop.This patch is a stop gap measure: Attempt to acquire the lock on the reader, if that failed switch to HDFS positional reads, which can read at an offset without affecting the state of the stream, and hence requires no locking.
Summary
Together these various changes can lead to ~40-50% scan performance improvement when using a single core. Even more when using multiple cores on the same machines (as is the case with HBase)An entirely unscientific benchmark
20m rows, with two column families just a few dozen bytes each.I performed two tests:
1. A scan that returns rows to the client
2. A scan that touches all rows via a filter but does not return anything to the client.
(This is useful to gauge the actual server side performance).
Further I tested with (1) no caching, all reads from disk (2) all data in the OS cache and (3) all data in HBase's block cache.
I compared 0.94.0 against the current 0.94 branch (what I will soon release as 0.94.4).
Results:
-
Scanning with scanner caching set to 10000:
-
0.94.0
no data in cache: 54s
data in OS cache: 51s
data in block cache: 35s
-
0.94.0
-
0.94.4-snapshot
no data in cache: 50s (IO bound between disk and network)
data in OS cache: 43s
data in block cache: 32s
(limiting factor was shipping the results to the client)
-
all data filtered at the server (with a SingleValueColumnFilter that does not match anything, so each rows is still scanned)
-
0.94.0
no data in cache: 31s
data in OS cache: 25s
data in block cache: 11s
-
0.94.0
-
0.94.4-snapshot
no data in cache: 22s
data in OS cache: 17s
cache in block cache: 6.3s
So as you can see scan performance has significantly improved since 0.94.0.
Salesforce just hired some performance engineers from a well known chip manufacturer, and I plan to get some of their time to analyze HBase in even more details, to track down memory stalls, etc.
原文地址:HBase Profiling, 感谢原作者分享。

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

隨著大數據時代的到來,資料處理和儲存變得越來越重要,如何有效率地管理和分析大量的資料也成為企業面臨的挑戰。 Hadoop和HBase作為Apache基金會的兩個項目,為大數據儲存和分析提供了一個解決方案。本文將介紹如何在Beego中使用Hadoop和HBase進行大數據儲存和查詢。一、Hadoop和HBase簡介Hadoop是一個開源的分散式儲存和運算系統,它可

依賴:org.springframework.dataspring-data-hadoop-hbase2.5.0.RELEASEorg.apache.hbasehbase-client1.1.2org.springframework.dataspring-data-hadoop2.5.0.RELEASE增加配置官方提供的方式是透過xml方式,簡單改寫後如下:@ConfigurationpublicclassHBaseConfiguration{@Value("${hbase.zooke

如何使用Java開發一個基於HBase的NoSQL資料庫應用引言:隨著大數據時代的到來,NoSQL資料庫成為處理大量資料的重要工具之一。 HBase作為一種開源的分散式NoSQL資料庫系統,在大數據領域有廣泛的應用。本文將介紹如何使用Java來開發基於HBase的NoSQL資料庫應用,並提供具體的程式碼範例。一、HBase介紹:HBase是基於Hadoop的分

随着互联网应用和数据量的不断增长,传统的关系型数据库已经不能满足存储和处理海量数据的需求。而NoSQL(NotOnlySQL)作为一种新型的数据库管理系统,其能够在海量数据存储和处理方面具有显著的优势,得到越来越多的关注和应用。在NoSQL数据库中,ApacheHBase是一个非常流行的开源分布式数据库,它基于Google的BigTable思想设计,具

隨著大數據時代的到來,海量資料的儲存和處理顯得格外重要。在NoSQL資料庫方面,HBase是目前廣泛應用的解決方案。 Go語言作為靜態強類型程式語言,由於其語法簡單、效能優秀,越來越多地應用於雲端運算、網站開發和資料科學等領域。本文將介紹如何在Go語言中使用HBase來實現高效率的NoSQL資料庫應用。 HBase介紹HBase是高可擴展、高可靠性、基

在Beego框架中使用HBase進行資料儲存和查詢隨著網路時代的不斷發展,資料儲存和查詢變得越來越關鍵。大數據時代來臨,各種資料來源都在各自不同的領域佔據著重要地位,其中非關係型資料庫是一種在資料儲存和查詢方面優勢明顯的資料庫,而HBase是一種基於Hadoop的分散式非關係型資料庫。本文將介紹如何在Beego框架中使用HBase進行資料儲存與查詢。一、H

Workerman是高效能的PHPsocket框架,它的特點是可以承載大量的並發連接。與傳統的PHP框架不同的是,Workerman不依賴Apache或Nginx等Web伺服器,而是透過開啟一個PHP進程,獨自運行整個應用程式。 Workerman具有極高的運作效率和更好的負載能力。同時,HBase是一個分散式的NoSQL資料庫系統,廣泛應用於大數

HBase是一個基於Hadoop的分散式儲存系統,旨在儲存和處理大規模結構化資料。為了優化它的讀寫效能,HBase提供了多種快取機制,可以透過合理的配置來提高查詢效率,減少讀寫延遲。本文將介紹HBase快取技術以及如何進行設定。 HBase快取種類HBase提供了兩種基本快取機制:區塊快取(BlockCache)和MemStore快取(也稱為寫入快取)。塊緩存是在
