-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfeed.xml
167 lines (125 loc) · 13.4 KB
/
feed.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>FlashSQL 기술 블로그</title>
<description></description>
<link>http://flashsql.github.io/</link>
<atom:link href="http://flashsql.github.io/feed.xml" rel="self" type="application/rss+xml"/>
<pubDate>Thu, 21 Feb 2019 15:32:42 +0900</pubDate>
<lastBuildDate>Thu, 21 Feb 2019 15:32:42 +0900</lastBuildDate>
<generator>Jekyll v3.8.5</generator>
<item>
<title>Punch Hole</title>
<description><h1 id="punch-hole">Punch hole</h1>
<p>아래 두 자료 참고해서 정리</p>
<ul>
<li><a href="https://mysqlserverteam.com/innodb-transparent-page-compression/">InnoDB Transparent Page Compression</a></li>
<li><a href="https://dev.mysql.com/doc/refman/5.7/en/innodb-page-compression.html">MySQL 5.7 Manual</a></li>
</ul>
<h2 id="transparent-page-compression">Transparent Page Compression</h2>
<p>InnoDB는 <a href="https://dev.mysql.com/doc/refman/8.0/en/glossary.html#glos_file_per_table">file-per-table</a> 테이블스페이스에 존재하는 테이블에 대해 <strong>페이지 레벨</strong> 압축을 지원한다. 이는 <em>Transparent Page Compression</em> 라 불린다. 페이지 압축은 <code class="highlighter-rouge">CREATE TABLE</code> 또는 <code class="highlighter-rouge">ALTER TABLE</code> 문에 <code class="highlighter-rouge">COMPRESSION</code> attribute를 명시하여 사용할 수 있으며, <em>Zlib</em>과 <em>LZ4</em> 압축 알고리즘을 지원한다. 예를 들어, 아래와 같이 사용할 수 있다:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>CREATE TABLE t1 <span class="o">(</span>c1 INT<span class="o">)</span> <span class="nv">COMPRESSION</span><span class="o">=</span><span class="s2">"zlib"</span><span class="p">;</span>
</code></pre></div></div>
<p>한편, <code class="highlighter-rouge">ALTER TABLE ... COMPRESSION</code>은 테이블스페이스의 압축 attribute만 업데이트한다(즉, metadata만 변경). 새 압축 알고리즘을 설정한 후에 발생하는 쓰기는 새로운 설정을 사용하지만, 기존 압축 페이지에 새 압축 알고리즘을 적용하려면 <code class="highlighter-rouge">OPTIMIZE TABLE</code>을 사용하여 테이블을 재빌드해야 한다:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ALTER TABLE t1 <span class="nv">COMPRESSION</span><span class="o">=</span><span class="s2">"zlib"</span><span class="p">;</span>
OPTIMIZE TABLE t1<span class="p">;</span>
</code></pre></div></div>
<p>High level에서 봤을 때, transparent page compression은 간단한 페이지 변환이다.</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Write : Page -&gt; Transform -&gt; Write transformed page to disk -&gt; Punch hole
Read : Page from disk -&gt; Transform -&gt; Original Page
</code></pre></div></div>
<p>MySQL 5.7에는 여러 개의 페이지 플러싱 전용 thread가 존재한다. 이는 디스크에 페이지를 쓰기 전에 전용 background thread로 “변환”을 오프로드하여 디스크에 기록한 후, 압축과 “hole punching”을 병렬 처리하는 데 적합하다.</p>
<p>그리고 transparent page compression 기능을 사용하려면 운영 체제와 파일 시스템이 <a href="https://en.wikipedia.org/wiki/Sparse_file">sparse files</a>과 hole punching을 지원해야 한다.</p>
<blockquote>
<p>Sparse file은 0이 아닌 영역에만 물리적인 디스크 공간을 할당하는 파일 유형으로써, 파일 자체가 부분적으로 비어 있는 경우 파일 시스템 공간을 보다 효율적으로 사용할 수 있음</p>
</blockquote>
<p align="center">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/9f/Sparse_file_%28en%29.svg/1024px-Sparse_file_%28en%29.svg.png" alt="sparse file" width="400" />
</p>
<h2 id="linux-상에서의-hole-punch-크기">Linux 상에서의 Hole Punch 크기</h2>
<p>Linux 시스템에서 파일 시스템의 블록 크기는 hole punching에 사용되는 단위 크기다. 따라서, 페이지 압축은 <code class="highlighter-rouge">InnoDB 페이지 크기 - 파일 시스템 블록 크기</code>보다 작거나 같은 크기로 압축될 수 있는 경우에만 작동한다. 예를 들어, <a href="https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_page_size">innodb_page_size</a>가 16KB고 파일 시스템 블록 크기가 4KB인 경우, hole punching을 가능하게 하려면 페이지 데이터를 12KB 이하로 압축해야 한다.</p>
<h2 id="monitoring">Monitoring</h2>
<p>Hole punching에서 <code class="highlighter-rouge">ls -l</code>로 보여지는 파일 크기는 블록 디바이스의 실제 할당 크기가 아닌 논리적 파일 크기를 표시한다. 이는 sparse file의 일반적인 이슈며, 논리적 크기와 실제 할당 크기는 <a href="https://dev.mysql.com/doc/refman/5.7/en/innodb-sys-tablespaces-table.html">INNODB_SYS_TABLESPACES</a>의 information schema 테이블에 쿼리를 수행하여 얻을 수 있다.</p>
<p>다음과 같은 추가적인 열이 information schema 뷰에 추가되었다: <code class="highlighter-rouge">FS_BLOCK_SIZE</code>, <code class="highlighter-rouge">FILE_SIZE</code>, <code class="highlighter-rouge">ALLOCATED_SIZE</code> 및 <code class="highlighter-rouge">COMPRESSION</code></p>
<ul>
<li><code class="highlighter-rouge">FS_BLOCK_SIZE</code>: 파일 시스템 블록 크기</li>
<li><code class="highlighter-rouge">FILE_SIZE</code>: 파일의 논리적 크기이며, ls -l로 볼 수 있음</li>
<li><code class="highlighter-rouge">ALLOCATED_SIZE</code>: 파일 시스템의 블록 디바이스에 실제로 할당된 크기</li>
<li><code class="highlighter-rouge">COMPRESSION</code>: 현재 압축 알고리즘 설정(있는 경우)</li>
</ul>
<blockquote>
<p>앞서 언급했듯이, <code class="highlighter-rouge">COMPRESSION</code> 값은 현재 테이블스페이스의 설정이며 현재 테이블스페이스에 있는 모든 페이지가 해당 형식을 갖는 것을 보장하지는 않는다.</p>
</blockquote>
<p>다음은 간단한 예시다:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mysql&gt; <span class="k">select</span> <span class="k">*</span> from information_schema.INNODB_SYS_TABLESPACES WHERE name like <span class="s1">'linkdb%'</span><span class="p">;</span>
+-------+------------------------+------+-------------+----------------------+-----------+---------------+------------+---------------+-------------+----------------+-------------+
| SPACE | NAME | FLAG | FILE_FORMAT | ROW_FORMAT | PAGE_SIZE | ZIP_PAGE_SIZE | SPACE_TYPE | FS_BLOCK_SIZE | FILE_SIZE | ALLOCATED_SIZE | COMPRESSION |
+-------+------------------------+------+-------------+----------------------+-----------+---------------+------------+---------------+-------------+----------------+-------------+
| 23 | linkdb/linktable#P#p0 | 0 | Antelope | Compact or Redundant | 16384 | 0 | Single | 512 | 4861198336 | 2376154112 | LZ4 |
</code></pre></div></div>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mysql&gt; <span class="k">select </span>name, <span class="o">((</span>file_size-allocated_size<span class="o">)</span><span class="k">*</span>100<span class="o">)</span>/file_size as compressed_pct from information_schema.INNODB_SYS_TABLESPACES WHERE name like <span class="s1">'linkdb%'</span><span class="p">;</span>
+------------------------+----------------+
| name | compressed_pct |
+------------------------+----------------+
| linkdb/linktable#P#p0 | 51.1323 |
| linkdb/linktable#P#p1 | 51.1794 |
| linkdb/linktable#P#p2 | 51.5254 |
| linkdb/linktable#P#p3 | 50.9341 |
| linkdb/linktable#P#p4 | 51.6542 |
| linkdb/linktable#P#p5 | 51.2027 |
| linkdb/linktable#P#p6 | 51.3837 |
| linkdb/linktable#P#p7 | 51.6309 |
| linkdb/linktable#P#p8 | 51.8193 |
| linkdb/linktable#P#p9 | 50.6776 |
| linkdb/linktable#P#p10 | 51.2959 |
| linkdb/linktable#P#p11 | 51.7169 |
| linkdb/linktable#P#p12 | 51.0571 |
| linkdb/linktable#P#p13 | 51.4743 |
| linkdb/linktable#P#p14 | 51.4895 |
| linkdb/linktable#P#p15 | 51.2749 |
| linkdb/counttable | 50.1664 |
| linkdb/nodetable | 31.2724 |
+------------------------+----------------+
18 rows <span class="k">in </span><span class="nb">set</span> <span class="o">(</span>0.00 sec<span class="o">)</span>
</code></pre></div></div>
<h2 id="limitations">Limitations</h2>
<h3 id="file-system-fragmentation">File system fragmentation</h3>
<p>블록을 파일 시스템의 free list로 다시 내보내는 hole punching으로 인해 파일 시스템에서 fragmentation이 일어날 수 있다. 여기에는 두 가지 파급 효과가 있다:</p>
<ol>
<li>Sequential 스캔이 실제로는 Random I/O로 끝날 수 있다. 이는 특히 HDD의 경우 문제가 된다.</li>
<li>FS free list 관리 오버 헤드가 증가할 수 있다.</li>
</ol>
</description>
<pubDate>Wed, 18 Apr 2018 17:43:59 +0900</pubDate>
<link>http://flashsql.github.io/mysql/2018/04/18/test9.html</link>
<guid isPermaLink="true">http://flashsql.github.io/mysql/2018/04/18/test9.html</guid>
<category>MySQL</category>
</item>
<item>
<title>Test</title>
<description><p>Linux 시스템에서 파일 시스템의 블록 크기는 hole punching에 사용되는 단위 크기다. 따라서, 페이지 압축은 InnoDB 페이지 크기 - 파일 시스템 블록 크기보다 작거나 같은 크기로 압축될 수 있는 경우에만 작동한다. 예를 들어, innodb_page_size가 16KB고 파일 시스템 블록 크기가 4KB인 경우, hole punching을 가능하게 하려면 페이지 데이터를 12KB 이하로 압축해야 한다.</p>
</description>
<pubDate>Wed, 18 Apr 2018 17:43:59 +0900</pubDate>
<link>http://flashsql.github.io/mysql/flash/2018/04/18/test.html</link>
<guid isPermaLink="true">http://flashsql.github.io/mysql/flash/2018/04/18/test.html</guid>
<category>MySQL</category>
<category>Flash</category>
</item>
<item>
<title>Dummy Post</title>
<description><p>This is just a dummy post. Lorem ipsum and all the rest.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</description>
<pubDate>Sat, 18 Apr 2015 17:43:59 +0900</pubDate>
<link>http://flashsql.github.io/mysql/rocksdb/2015/04/18/dummy.html</link>
<guid isPermaLink="true">http://flashsql.github.io/mysql/rocksdb/2015/04/18/dummy.html</guid>
<category>MySQL</category>
<category>RocksDB</category>
</item>
</channel>
</rss>