-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1135 lines (466 loc) · 32.4 KB
/
Copy pathindex.html
File metadata and controls
1135 lines (466 loc) · 32.4 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="theme-next muse use-motion" lang="zh-CN">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">
<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">
<link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">
<meta name="keywords" content="Hexo, NexT" />
<meta name="description">
<meta property="og:type" content="website">
<meta property="og:title" content="Don't Panic">
<meta property="og:url" content="http://theflyfish.github.io/index.html">
<meta property="og:site_name" content="Don't Panic">
<meta property="og:description">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Don't Panic">
<meta name="twitter:description">
<script type="text/javascript" id="hexo.configurations">
var NexT = window.NexT || {};
var CONFIG = {
root: '/',
scheme: 'Muse',
version: '5.1.4',
sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
fancybox: true,
tabs: true,
motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
duoshuo: {
userId: '0',
author: 'Author'
},
algolia: {
applicationID: '',
apiKey: '',
indexName: '',
hits: {"per_page":10},
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
}
};
</script>
<link rel="canonical" href="http://theflyfish.github.io/"/>
<title>Don't Panic</title>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">
<div class="container sidebar-position-left
page-home">
<div class="headband"></div>
<header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-wrapper">
<div class="site-meta ">
<div class="custom-logo-site-title">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">Don't Panic</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle">stay hungry, stay foolish</p>
</div>
<div class="site-nav-toggle">
<button>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section">
<i class="menu-item-icon fa fa-fw fa-home"></i> <br />
Home
</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section">
<i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
Archives
</a>
</li>
</ul>
</nav>
</div>
</header>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<section id="posts" class="posts-expand">
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://theflyfish.github.io/2019/02/18/ctcdflow-readme/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Shine Yu">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Don't Panic">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/02/18/ctcdflow-readme/" itemprop="url">Untitled</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Post created" itemprop="dateCreated datePublished" datetime="2019-02-18T00:04:00+08:00">
2019-02-18
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h4 id="ctcdflow代码框架"><a href="#ctcdflow代码框架" class="headerlink" title="ctcdflow代码框架"></a>ctcdflow代码框架</h4><h3 id="流程框架"><a href="#流程框架" class="headerlink" title="流程框架"></a>流程框架</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">st1=>start: ctcdflow framework</span><br><span class="line">e=>end: category implement</span><br><span class="line">op1=>operation: opreation dict</span><br><span class="line">op2=>operation: category factory</span><br><span class="line">st1->op1</span><br><span class="line">op1->op2</span><br></pre></td></tr></table></figure>
<h3 id="framework概述"><a href="#framework概述" class="headerlink" title="framework概述"></a>framework概述</h3><p>framework基于python的argparse的子命令方式,将各个step的任务处理进行了解耦</p>
<p>以下是framework下的目录架构除tools目录外其他每个目录代表ctcd流程中的某一步step,与该操作相关的所有代码文件都聚合到该目录下,每一个step作为一个插件接入到framework里。</p>
<blockquote>
<p>├── engine_deploy<br>├── model_deploy<br>├── model_evaluate<br>├── model_predict<br>├── model_prepare<br>├── model_recycle<br>├── model_train<br>├── serving_check<br>└── tools<br>如果需要新增子命令时,只需要遵循相关的插件定义方式即可</p>
</blockquote>
<figure class="highlight aspectj"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">OP_DICT = {</span><br><span class="line"> <span class="string">'model_train'</span>: ModelTrainOp(),</span><br><span class="line"> 'model_prepare': ModelPrepareOp(),</span><br><span class="line"> 'model_predict': ModelPredictOp(),</span><br><span class="line"> 'model_evaluate': ModelEvaluateOp(),</span><br><span class="line"> 'model_deploy': ModelDeployOp(),</span><br><span class="line"> 'model_recycle': ModelRecycleOp(),</span><br><span class="line"> 'serving_check': ServingCheckOp(),</span><br><span class="line"> 'engine_deploy':EngineDeployOp()</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>然后具体到每个Step内部,代码结构如下:</p>
<blockquote>
<p>├── factory.py<br>├── op.py<br>├── base<br>├── fm<br>├── lr</p>
</blockquote>
<p>op.py:<br>其中op.py中定义了step接入framework的方式,其中包括</p>
<ul>
<li>定义framwork中与该step相关的输入参数</li>
<li>定义framwork调用该step时的入口操作函数<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ModelPrepareOp</span><span class="params">()</span>:</span></span><br><span class="line"><span class="meta"> @staticmethod</span></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">set_argument</span><span class="params">(subparser)</span>:</span></span><br><span class="line"> subparser.add_argument(<span class="string">'--model_name'</span>,help = <span class="string">"model name"</span>)</span><br><span class="line"> subparser.add_argument(<span class="string">'--model_version'</span>,help= <span class="string">"model version"</span>)</span><br><span class="line"> subparser.set_defaults(func = ModelPrepareOp.run)</span><br><span class="line"><span class="meta"> @staticmethod</span></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">run</span><span class="params">(args)</span>:</span></span><br><span class="line"> module_logger.info(<span class="string">"args:%s"</span> % args)</span><br><span class="line"> instance = ModelPrepareFactory.create(args.model_source)</span><br><span class="line"> instance.init(args)</span><br><span class="line"> instance.process()</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>factory.py:<br>因为每个step执行时,根据某些类型不一致,具体的执行流程也不一致,以上述例子为例,不同的算法对应不同的执行流程。所以在这里定义了定义了工厂类,根据入参来反射查找对应的执行类<br>base:<br>base目录下存储了通用的操作定义,所有具体执行类的基础类接口interface也在此定义;具体执行类必须继承自interface接口进行重载实现。在上述例子中fm与lr目录下即存放了具体执行子类的代码逻辑</p>
<h3 id="step-操作说明"><a href="#step-操作说明" class="headerlink" title="step 操作说明"></a>step 操作说明</h3><h4 id="model-prepare"><a href="#model-prepare" class="headerlink" title="model_prepare"></a>model_prepare</h4><p>模型准备,在weips模式下,内部流程包括模型保存、模型转化、模型库注册等</p>
<h4 id="model-evaluate"><a href="#model-evaluate" class="headerlink" title="model_evaluate"></a>model_evaluate</h4><p>模型评估</p>
<h4 id="model-deploy"><a href="#model-deploy" class="headerlink" title="model_deploy"></a>model_deploy</h4><p>模型部署</p>
<h4 id="engine-deploy"><a href="#engine-deploy" class="headerlink" title="engine_deploy"></a>engine_deploy</h4>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://theflyfish.github.io/2018/12/24/weiPSClient/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Shine Yu">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Don't Panic">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2018/12/24/weiPSClient/" itemprop="url">Untitled</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Post created" itemprop="dateCreated datePublished" datetime="2018-12-24T19:15:00+08:00">
2018-12-24
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://theflyfish.github.io/2016/02/28/notes-1/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Shine Yu">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Don't Panic">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2016/02/28/notes-1/" itemprop="url">大规模分布式系统_原理分析与架构实践</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Post created" itemprop="dateCreated datePublished" datetime="2016-02-28T22:50:35+08:00">
2016-02-28
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="1-分布式存储定义"><a href="#1-分布式存储定义" class="headerlink" title="1. 分布式存储定义"></a>1. 分布式存储定义</h2><ul>
<li>大量普通PC服务器通过internet互联,对外作为一个整体提供存储服务</li>
</ul>
<h2 id="2-特性"><a href="#2-特性" class="headerlink" title="2. 特性"></a>2. 特性</h2><ul>
<li>扩展性,低成本,高性能,易用性</li>
</ul>
<h2 id="3-挑战难点"><a href="#3-挑战难点" class="headerlink" title="3. 挑战难点"></a>3. 挑战难点</h2><ul>
<li>数据与状态信息的持久化</li>
<li>在自动迁移与自读容错,并发读写的过程中保证数据的一致性</li>
</ul>
<h2 id="4-数据类型分类"><a href="#4-数据类型分类" class="headerlink" title="4. 数据类型分类"></a>4. 数据类型分类</h2><ul>
<li>非结构化数据</li>
<li>结构化数据</li>
<li>半结构化数据</li>
</ul>
<h2 id="5-分布式存储分类:"><a href="#5-分布式存储分类:" class="headerlink" title="5.分布式存储分类:"></a>5.分布式存储分类:</h2><ul>
<li>分布式文件系统</li>
<li>作为分布式表格系统与分布式数据库的的底层存储 <ul>
<li>Facebook Haystack</li>
<li>TFS\GFS\Amazon EBS</li>
</ul>
</li>
<li>分布式键值系统<ul>
<li>memcache\Tair\Amazon Dynamo</li>
</ul>
</li>
<li>分布式表格系统 <ul>
<li>Google Bigtable</li>
<li>megastore</li>
<li>Microsoft azure table storage</li>
<li>Amazon DynamoDB</li>
</ul>
</li>
<li>分布式数据库<ul>
<li>MySQL sharding</li>
<li>Amazon RDS</li>
<li>Microsoft SQL azure</li>
<li>Google spanner</li>
<li>OceanBase</li>
</ul>
</li>
</ul>
<h2 id="6-OTHER"><a href="#6-OTHER" class="headerlink" title="6. OTHER"></a>6. OTHER</h2><ul>
<li>性能瓶颈: <ul>
<li>存储系统的性能瓶颈主要在于磁盘的随机读写</li>
</ul>
</li>
<li><p>优化方式:</p>
<ul>
<li><p>将随机写操作转化为顺序写</p>
<pre><code>>Log-structured Merge Tree 这套体系的核心思路就是,你的所有更新和删除操作,都会被转换为一个log并被追加到文件尾部,这样就可以将所有的原位更新都转换为顺序写入,代价则是更多的读取次数,不过因为NAND的读取不是瓶颈,所以代价是可以接受的.同时,后端有一组线程,从文件头开始顺序的读取所有的块,将块中未被标记为删除的数据找出来,凑够64个页后写到新的块中,然后调用块删除命令,清除那些已经完成誊写的数据块。
</code></pre></li>
<li><p>通过缓存减少磁盘随机读操作</p>
<pre><code>>缓存
</code></pre></li>
</ul>
</li>
</ul>
<ul>
<li>SSD随机读取友好,随机写入时存在写入放大问题</li>
</ul>
<h2 id="分布式系统衡量指标"><a href="#分布式系统衡量指标" class="headerlink" title="分布式系统衡量指标"></a>分布式系统衡量指标</h2><ul>
<li><strong>性能</strong><ul>
<li>吞吐能力与系统响应时间</li>
</ul>
</li>
<li>可用性<ul>
<li>指系统在面对各种异常时可以提供正常服务的能力,可用性可以用系统停服务的时间与正常服务的时间的比例来衡量</li>
</ul>
</li>
<li>一致性 <ul>
<li>越是强的一致性模型,用户使用起来越简单</li>
</ul>
</li>
<li>可扩展性</li>
</ul>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://theflyfish.github.io/2016/01/15/snapshot/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Shine Yu">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Don't Panic">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2016/01/15/snapshot/" itemprop="url">使用带权计数算法对快照机制优化</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Post created" itemprop="dateCreated datePublished" datetime="2016-01-15T20:10:33+08:00">
2016-01-15
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="1-背景"><a href="#1-背景" class="headerlink" title="1. 背景"></a>1. 背景</h2><p>当前快照机制使用世代引用计数算法(generational referencecounting),来判定对象是否需要删除。<br>但该算法无法实现legder对象空间复用,就导致了如果快照个数达到最大值,即使删除已创建快照,也无法创建新快照。<br>当前每次删除快照时,每删除一个对象都需要操作一个ledger记账对象,导致快照删除的性能很差<br>现在考虑使用带权计数算法进行优化,旨在解决ledger对象复用的问题,并尝试根据新的算法解决快照性能的不足。</p>
<h2 id="2-基于带权算法的快照机制"><a href="#2-基于带权算法的快照机制" class="headerlink" title="2. 基于带权算法的快照机制"></a>2. 基于带权算法的快照机制</h2><ol>
<li>每个数据对象创建后都有一个固定的总权重TW(total weight),原始权重OW(original weight).最初时TW=OW=2^63,TW与OW值由ledger对象来管理</li>
<li>每个引用该对象的VDI都会维护一个对应的权重PW(partial weight),由于每个VDI由很多对象构成,会在inode中记录一个PW数组,以下以单个对象为例进行说明。</li>
<li>第一个VDI创建时,OW会传递1/2的权重到该VDI,即此时OW=2^62,PW1=2^62</li>
<li>每创建一个VDI,该VDI都会得到父VDI 1/2的权重,同时父VDI的权重变为原来的1/2<br><img src="/images/Image-1.png" alt="snapshot"></li>
<li><p>依此类推,在基于原始对象创建一个新的VDI(snapshot或者clone)时,当前VDI会将自身持有权重PW的1/2传递到下一个VDI中</p>
</li>
<li><p>VDI删除时,操作ledger对象 将这个VDI的权重加回到OW中</p>
</li>
<li>当TW==OW时,代表该对象已经没有VDI引用,触发删除操作</li>
<li>以上便是整个算法的骨架,该算法维护这样一个核心恒等式: TW =OW+(PW1+PW2+….+PWn), PWn表示第N个引用该对象的VDI的权重</li>
</ol>
<h2 id="3-边界处理与OW权重池"><a href="#3-边界处理与OW权重池" class="headerlink" title="3. 边界处理与OW权重池"></a>3. 边界处理与OW权重池</h2><h3 id="边界问题"><a href="#边界问题" class="headerlink" title="边界问题"></a>边界问题</h3><ul>
<li>如果一个VDI-x的权重已经为1,若还要基于其创建新VDI-y,需要判断ledger对象,进行如下流程:<ul>
<li>如果OW不为1,说明还有多余的权重可以分配,PW(x)=OW/2+PW(x), 从OW中分取一半的权重,继续进行后续的VDI创建流程. </li>
<li>如果OW为1, 说明该对象权重已经全部用完,无法继续分配。</li>
</ul>
</li>
</ul>
<h3 id="应对方案"><a href="#应对方案" class="headerlink" title="应对方案"></a>应对方案</h3><ul>
<li>针对此问题有两个方案可以解决:<ul>
<li>通过增加总权重TW的方式增加可用权重</li>
<li>创建新的权重对象OW2。</li>
</ul>
</li>
<li>此处参考相关资料使用间接块的想法,初步设计采用权重池的方式</li>
</ul>
<p>###权重池机制</p>
<ol>
<li>首先在ledger中维护32(个数待定)个OW权重数组OW[32],每个OW初值均为TW</li>
<li>每个引用该对象的VDI,维护两个变量,generation与PW值,generation代表该权重所属的OW在OW数组中的位置。</li>
<li>开始创建第一个vdi时使用OW[0]作为原始权重,generation=0,按照第二节的规律后续的vdi依次创建</li>
<li>回到上面的问题,当某个VDI-x权重为1且需要基于该VDI进行创建新VDI-y,如果OW[0]为1,已经无法分配权重,此时我们进行如下操作:<ul>
<li>VDI-x将之前分配得到的权重还回OW[0]</li>
<li>选择OW[1]重进行分配,此时PW(x)= OW[1]/2;当VDI-x得到足够的权重,便可继续进行VDI创建</li>
<li>更新VDI-x的generation=1;</li>
</ul>
</li>
<li>当VDI删除时,根据自身的generation将PW还回到对应的OW中</li>
<li>当整个ledger数组的OW都等于TW时,该对象已经么有引用,触发删操作</li>
</ol>
<h2 id="4-结论讨论"><a href="#4-结论讨论" class="headerlink" title="4. 结论讨论"></a>4. 结论讨论</h2><ol>
<li>snapshot的原来的机制采用世代引用计数算法(GRC),带权引用计数算法(WRC)与之对比如下:<br><img src="/images/Image-2.png" alt="snapshot"></li>
<li><p>针对该方案,进行初步理论值统计 </p>
<ul>
<li><p>MIN:在最差的情况下能够使用的快照个数。最差情况是指对同一个VDI只进行连续的快照操作,此时权重的消耗速度最快,判断为目前最差的情况,此种情况下总的快照次数计算公式为</p>
<blockquote>
<p>sum =n(n+1)/2, n为总权重的幂数 </p>
</blockquote>
</li>
<li><p>MAX: 整个VDI即有clone也有snapshot,这个VDI以二叉树的方式全部铺开(参考意义不大)<br><img src="/images/Image-3.jpg" alt="snapshot"></p>
</li>
</ul>
</li>
<li><p>当权重为1的VDI需要打快照时,就会导致快照创建时也会操作记账对象</p>
<blockquote>
<p>以2^31为TW总权重为例,在最差MIN情况下,每465快照中有30次快照,创建时会操作记账对象</p>
</blockquote>
</li>
<li><p>该优化方案,对代码的改动面较大,改动过程中需要考虑的比较全面,有出现新问题的风险,在做优化之前先把细节想清楚</p>
</li>
</ol>
<h2 id="5-基于WRC的快照性能优化(后续)"><a href="#5-基于WRC的快照性能优化(后续)" class="headerlink" title="5. 基于WRC的快照性能优化(后续)"></a>5. 基于WRC的快照性能优化(后续)</h2><ol>
<li>对于4T的VDI进行快照,若此时权重为1需要跟记账对象通信,按照每个对象4M计算,最差情况下大约有1M次的socket通信,可能会导致本次快照时间过长,快照的创建性能有会有波动。而且现在的机制中每个对象都对应一个ledger,在删除过程中最差情况会有1M次的socket通信,快照的删除性能比较差。</li>
<li>上述提到的问题,有两个优化方案<ul>
<li>由上一章节的理论数据可知,当ledger大小为1个字节时,数据对象支持快照个数可达4960个,如果这个个数已经达到要求的话,根据这一点我们可以用一个ledger对象管理一个VDI的所有对象,ledger中的每个字节与VDI中数据对象一一对应。对于4T的数据盘而言,ledger对象为4M大大减少了创建跟删除时的网络通信以及ledger对象的创建所耗费的时间。会对性能有很大的提升</li>
<li>第二个方案是一个ledger对象管理连续index的多个数据对象,通过hash的方式进行对象定位,通过这种方式,删除时理想情况下每删除256个对象,操作一次ledger对象</li>
</ul>
</li>
</ol>
<h2 id="6-参考文献"><a href="#6-参考文献" class="headerlink" title="6. 参考文献"></a>6. 参考文献</h2><p>Garbage Collection Algorithms For Automatic Dynamic Memory Management -Richard Jones<br>《垃圾收集》英文译- Richard Jones<br><a href="https://en.wikipedia.org/wiki/Reference_counting" target="_blank" rel="external">https://en.wikipedia.org/wiki/Reference_counting</a><br><a href="http://www.cse.scu.edu/~jholliday/COEN317S06/DC3Naming.ppt" target="_blank" rel="external">http://www.cse.scu.edu/~jholliday/COEN317S06/DC3Naming.ppt</a><br><a href="http://www.cs.nyu.edu/goldberg/pubs/gold89.pdf" target="_blank" rel="external">http://www.cs.nyu.edu/goldberg/pubs/gold89.pdf</a><br><a href="http://students.depaul.edu/~cbaier1/435/ds-log.html" target="_blank" rel="external">http://students.depaul.edu/~cbaier1/435/ds-log.html</a><br><a href="https://www.researchgate.net/publication/220758907_Cyclic_Weighted_Reference_Counting_without_Delay" target="_blank" rel="external">https://www.researchgate.net/publication/220758907_Cyclic_Weighted_Reference_Counting_without_Delay</a> </p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
</section>
</div>
</div>
<div class="sidebar-toggle">
<div class="sidebar-toggle-line-wrap">
<span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
<span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
<span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
</div>
</div>
<aside id="sidebar" class="sidebar">
<div class="sidebar-inner">
<section class="site-overview-wrap sidebar-panel sidebar-panel-active">
<div class="site-overview">
<div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
<p class="site-author-name" itemprop="name">Shine Yu</p>
<p class="site-description motion-element" itemprop="description"></p>
</div>
<nav class="site-state motion-element">
<div class="site-state-item site-state-posts">
<a href="/archives/">
<span class="site-state-item-count">4</span>
<span class="site-state-item-name">posts</span>
</a>
</div>
</nav>
</div>
</section>
</div>
</aside>
</div>
</main>
<footer id="footer" class="footer">
<div class="footer-inner">
<div class="copyright">© <span itemprop="copyrightYear">2019</span>
<span class="with-love">
<i class="fa fa-user"></i>
</span>
<span class="author" itemprop="copyrightHolder">Shine Yu</span>
</div>
<div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>
<span class="post-meta-divider">|</span>
<div class="theme-info">Theme — <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>
</div>
</footer>
<div class="back-to-top">
<i class="fa fa-arrow-up"></i>
</div>
</div>