-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLecture 16 Cache Consistency Memcached at Facebook.srt
4989 lines (4154 loc) · 144 KB
/
Lecture 16 Cache Consistency Memcached at Facebook.srt
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
1
00:00:01,520 --> 00:00:10,920
好的,大家好,我今天要谈论这篇文章
all right hello everyone I'm today going
to talk about this paper about how
2
00:00:10,920 --> 00:00:19,109
Facebook使用Memcache是为了处理巨大的负载
Facebook uses memcache I'm in order to
handle enormous load the reason we're
3
00:00:19,109 --> 00:00:23,750
阅读本文是因为这是一份经验论文,实际上没有任何内容
reading this paper is that it's an
experience paper there's not really any
4
00:00:23,750 --> 00:00:32,510
这里有新的概念,想法或技术,但这有点像是真实的生活
new concepts or ideas or techniques here
but it's kind of what a real live
5
00:00:32,840 --> 00:00:38,460
公司在尝试建立非常高的容量时遇到了麻烦
company ran into when they were trying
to build very high capacity
6
00:00:38,460 --> 00:00:44,160
基础设施您可以通过多种方式阅读它,一种是
infrastructure there's a couple of ways
you could read it one is a sort of
7
00:00:44,160 --> 00:00:49,800
关于如果您不认真对待一致性会出问题的警告性故事
cautionary tale about what goes wrong if
you don't take consistency seriously
8
00:00:49,800 --> 00:00:55,199
从一开始,另一种阅读方式就是关于这
from the start another way to read it is
that it's an impressive story about how
9
00:00:55,199 --> 00:01:02,300
通过使用大多数现成的软件获得极高的容量
to get extremely high capacity from
using mostly off-the-shelf software
10
00:01:03,019 --> 00:01:08,250
另一种阅读方式是它是一种说明或基本
another way to read it is that it's a
kind of illustration or the fundamental
11
00:01:08,250 --> 00:01:13,470
在试图变得很高之间,很多设置都面临着挣扎
struggle that a lot of setups face
between trying to get very high
12
00:01:13,470 --> 00:01:18,299
通过复制等方法以及如何保持一致性来实现的性能
performance which you do by things like
replication and how to give consistency
13
00:01:18,299 --> 00:01:24,180
像复制这样的技术真的是敌人,所以你知道我们
for which techniques like replication
are really the enemy and so you know we
14
00:01:24,180 --> 00:01:28,770
可以争论我们是否喜欢他们的设计,还是认为它是优雅的还是
can argue about whether we like their
design or we think it's elegant or a
15
00:01:28,770 --> 00:01:35,850
很好的解决方案,但我们不能真正与他们取得的成功争论不休,因此
good solution but we can't really argue
with how successful they've been so we
16
00:01:35,850 --> 00:01:40,020
确实需要认真对待它们,对我来说,实际上我首先
do need to take them seriously and for
me actually this paper which I first
17
00:01:40,020 --> 00:01:45,659
读了很多年前,我一直在想这件事,
read quite a few years ago it's been I
thought about it a lot and it's been
18
00:01:45,659 --> 00:01:55,170
各种各样的想法和对问题的理解的来源
sort of a source of sort of ideas and
understanding about problems at many
19
00:01:55,170 --> 00:01:57,380
点数
points
20
00:01:57,890 --> 00:02:03,240
好的,所以在适当谈论Facebook之前,您知道他们是
all right so before talking about
Facebook proper you know they're an
21
00:02:03,240 --> 00:02:07,619
您经常看到或有很多人拥有的模式示例
example of a pattern that you see fairly
often or that many people have
22
00:02:07,619 --> 00:02:11,068
他们尝试建立网站来做某事的经验丰富,而您
experienced in which they're trying to
build a website to do something and you
23
00:02:11,068 --> 00:02:15,000
通常知道建立网站的人对建立高级网站不感兴趣
know typically people who build websites
are not interested in building high
24
00:02:15,000 --> 00:02:22,200
您知道的高性能高性能存储基础架构
performance you know high performance
storage infrastructure they're
25
00:02:22,200 --> 00:02:26,940
对构建使用户满意或出售的功能感兴趣
interested in building features that
will make their users happy or selling
26
00:02:26,940 --> 00:02:31,290
更多广告或您所知道的东西,所以它们不会以
more advertisements or something you
know so they they're not gonna start by
27
00:02:31,290 --> 00:02:35,400
花大量的时间或大量的时间来建立自己的风格
spending a main year of effort or a
whole lot of time building cool
28
00:02:35,400 --> 00:02:38,340
他们将首先构建基础设施,然后对其进行排序
infrastructure they're gonna start by
building features in that they'll sort
29
00:02:38,340 --> 00:02:42,989
仅在他们真正必须做到的范围内使基础设施更好
of make infrastructure better only to
the extent that they really have to
30
00:02:42,989 --> 00:02:47,910
因为你知道那是他们时间的最佳利用,所以这是一个典型的开始
because you know that's the best use of
their time alright so a typical starting
31
00:02:47,910 --> 00:02:54,180
一个网站很小的情况下的场景,您知道没有
scenario in a ways when a some website
is very small is you know there's no
32
00:02:54,180 --> 00:02:57,569
不仅可以从一台机器开始,还可以
point in starting with anything more
than just a single machine right you
33
00:02:57,569 --> 00:03:01,980
知道也许您刚开始时只有几个用户坐在他们前面
know maybe you started you only have a
couple users sitting in front of their
34
00:03:01,980 --> 00:03:07,260
浏览器,您知道他们在这里与您的单机通过Internet进行通信
browsers and you know they talk over the
internet here with your single machine
35
00:03:07,260 --> 00:03:16,170
您的单台计算机可能现在要运行Apache Web服务器,也许您
your single machine is gonna maybe run
the Apache web server now maybe you
36
00:03:16,170 --> 00:03:23,970
使用PHP或Python或其他一些语言编写用于生成网页的脚本
write the scripts that produce web pages
using PHP or Python or some other
37
00:03:23,970 --> 00:03:29,340
方便,易于编程的脚本风格语言和Facebook
convenient easy to program sort of
scripting style language and Facebook
38
00:03:29,340 --> 00:03:36,000
使用PHP,您需要将数据存储在某个地方,也可以下载排序
uses PHP you need to store your data
somewhere or you can just download sort
39
00:03:36,000 --> 00:03:42,630
的标准数据库和Facebook碰巧使用了我的续集,我的学校很好
of standard database and Facebook happen
to use my sequel my school is a good
40
00:03:42,630 --> 00:03:49,079
选择,因为它实现了续集查询语言,功能非常强大且功能强大
choice because it implements the sequel
query language is very powerful and acid
41
00:03:49,079 --> 00:03:54,930
事务提供了持久的存储,所以这就像一个非常好的设置
transactions provides durable storage so
this is like a very very nice set up I
42
00:03:54,930 --> 00:04:00,450
其实我会带你走很长一段路,但是假设你成功了
am will take you a long way actually but
supposing supposing you get successful
43
00:04:00,450 --> 00:04:04,350
您获得越来越多的用户,您知道您将获得越来越多的负载
you get more and more users you know
you're gonna get more and more load more
44
00:04:04,350 --> 00:04:09,900
越来越多的人将浏览您的网站并运行任何PHP东西
and more people gonna be viewing your
website and running whatever PHP stuff
45
00:04:09,900 --> 00:04:14,970
您可以使用网站提供的内容,因此在某些时候
you're with
site provides and so at some point
46
00:04:14,970 --> 00:04:19,290
几乎可以肯定,第一个出错的地方是PHP
almost certainly the first thing that's
going to go wrong is that the PHP
47
00:04:19,290 --> 00:04:25,650
脚本会占用过多的CPU时间,这通常是第一个瓶颈
scripts are gonna take up too much CPU
time that's usually the first bottleneck
48
00:04:25,650 --> 00:04:29,850
如果他们从单个服务器开始,人们就会遇到,所以您需要的是一些
people encounter if they start with a
single server so what you need is some
49
00:04:29,850 --> 00:04:33,840
为您的PHP脚本获得更多功能的方法,这使我们能够
way to get more horsepower for your PHP
scripts and so that takes us to kind of
50
00:04:33,840 --> 00:04:40,470
您知道其中有很多网站的网站的第二架构
architecture number two for websites in
which you know you have lots and lots of
51
00:04:40,470 --> 00:04:47,400
比以前需要更多CPU功能的用户数量更多的用户
users right or more users than before
you need more CPU power for your PHP
52
00:04:47,400 --> 00:04:53,520
脚本,因此您可以运行一堆前端服务器,其唯一的工作就是运行Web
scripts so you run a bunch of front end
servers whose only job is to run the web
53
00:04:53,520 --> 00:05:00,479
用户浏览器与之通信的服务器,这些服务器称为前端服务器,因此
servers that users browsers talk to and
these are called front end servers so
54
00:05:00,479 --> 00:05:03,860
这些都将运行补丁
these are going to run a patch either
55
00:05:04,650 --> 00:05:10,560
网络服务器和PHP脚本现在您知道用户将要与之交谈
webserver and the PHP scripts now you
know you users are going to talk to
56
00:05:10,560 --> 00:05:14,610
在不同时间使用不同的服务器,也许您的用户将彼此正交
different servers at different times
maybe your users Quadra each other they
57
00:05:14,610 --> 00:05:17,460
互相发消息,他们需要对方的信息或其他内容
message each other they need to see each
other's posts or something
58
00:05:17,460 --> 00:05:22,699
因此所有这些前端服务器都需要查看相同的后端数据
so all these front-end servers are going
to need to see the same back-end data
59
00:05:23,210 --> 00:05:28,889
为了做到这一点,您可能至少只能坚持一会儿
and in order to do that you probably
can't just stick at least for a while
60
00:05:28,889 --> 00:05:31,500
您可以只使用一个数据库服务器,这样您就可以拥有一个
you can just stick with one database
server so you gonna have a single
61
00:05:31,500 --> 00:05:37,770
机器已经是我处理所有数据库所有查询的续集,并且
machine already my sequel that handles
all of the database all queries and
62
00:05:37,770 --> 00:05:43,199
更新从前端服务器读取和写入,如果可以的话,
updates reads and writes from the front
end servers and if you possibly can it's
63
00:05:43,199 --> 00:05:46,560
明智的做法是在这里使用一台服务器,因为一旦您使用两台服务器,
wise to use a single server here because
as soon as you go with two servers and
64
00:05:46,560 --> 00:05:51,620
以某种方式,您在多个数据库服务器上的数据变得更加复杂
somehow your data over multiple database
servers like gets much more complicated
65
00:05:51,620 --> 00:05:56,550
您需要担心是否需要分布式交易或
and you need to worry about things like
do you need distributed transactions or
66
00:05:56,550 --> 00:06:01,590
它如何使用PHP脚本决定与哪个数据库服务器进行通讯,等等
how it has the PHP scripts decide which
database server to talk to and so again
67
00:06:01,590 --> 00:06:05,699
使用第二种架构,您可以获得很长的路要走
you can get a long way with this second
architecture you have as much CPU power
68
00:06:05,699 --> 00:06:11,880
您可以根据需要添加更多前端服务器,最多可以添加一个
as you like by adding more front end
servers and up to a point a single
69
00:06:11,880 --> 00:06:16,020
数据库服务器实际上将能够吸收许多前端的原因权限
database server will actually be able to
absorb the reason rights of many front
70
00:06:16,020 --> 00:06:22,610
结束,但您知道您可能会非常成功,您会获得更多用户,并且
ends but you know maybe you're very
successful you get even more users and
71
00:06:22,610 --> 00:06:27,599
所以问题是接下来会出什么问题,通常接下来会出什么问题
so the question is what's gonna go wrong
next and typically what goes wrong next
72
00:06:27,599 --> 00:06:33,169
是数据库服务器,因为您总是可以添加更多CPU和更多Web服务器
is that the database server since you
can always add more CPU more web servers
73
00:06:33,169 --> 00:06:37,620
您知道不可避免的错误是数据库服务器过了一段时间
you know what inevitably goes wrong is
that after a while the database server
74
00:06:37,620 --> 00:06:49,380
用完了好吧,这是网络的下一个架构是什么
runs out of steam okay so what's the
next architecture this is web
75
00:06:49,380 --> 00:06:55,080
建筑3和大型网站的标准演变方式
architecture 3 and the kind of standard
evolution of big websites here we have
76
00:06:55,080 --> 00:07:01,500
如果您现在知道成千上万的用户,而且很多
the same if you know now thousands and
thousands of users lots and lots of
77
00:07:01,500 --> 00:07:07,909
前端,现在我们基本上我们知道我们将不得不拥有多个
front ends and now we basically we know
we're gonna have to have multiple
78
00:07:07,909 --> 00:07:14,159
数据库服务器,所以现在在前端后面,我们拥有一整套数据库
database servers so now behind the front
ends we have a whole rack of database
79
00:07:14,159 --> 00:07:18,280
服务器每个人再次运行我的续集
servers each one of them running my
sequel again
80
00:07:18,280 --> 00:07:22,960
但是我们将分片现在驱动的数据以分片数据
but we're going to shard the data
we're driven now to sharding the data
81
00:07:22,960 --> 00:07:27,130
通过数据库服务器,所以您可能知道第一个拥有您知道的密钥
over the database server so you know
maybe the first one holds keys you know
82
00:07:27,130 --> 00:07:34,660
a到G&G到第二个,按住G到Q,你知道
a through G & G through second one holds
keys G through Q and you know whatever
83
00:07:34,660 --> 00:07:38,680
图表恰好是现在,您知道要教的前端
the charting happens to be and now the
front-end you know you have to teach
84
00:07:38,680 --> 00:07:42,250
您的PHP脚本在这里查看它们所需的数据并尝试找出
your PHP scripts here to look at the
data they need and try to figure out
85
00:07:42,250 --> 00:07:45,100
他们将在不同时间与之交谈的数据库服务器
which database server they're going to
talk to it you know in different times
86
00:07:45,100 --> 00:07:50,250
对于不同的数据,他们将与不同的服务器通信,因此这是分片的
for different data they're going to talk
to different servers so this is sharding
87
00:07:51,030 --> 00:07:57,460
当然,之所以能为您带来帮助,是因为现在所有的工作
and of course the reason why this gives
you a boost is that now the all the work
88
00:07:57,460 --> 00:08:01,360
阅读和写作的分裂,希望可以平均地分裂
of reading and writing has split up
hopefully hopefully evenly split up
89
00:08:01,360 --> 00:08:05,830
在这些服务器之间,因为它们保存不同的数据,所以现在可以复制评级字
between these servers since they hold
different data now replicas rating word
90
00:08:05,830 --> 00:08:09,960
绘制数据图表,它们可以并行执行并具有很大的并行度
charting the data and they can execute
in parallel and have big parallel
91
00:08:09,960 --> 00:08:17,110
读取和写入数据的能力,PHP代码必须要痛苦一些
capacity to read and write data it's a
little bit painful the PHP code has to
92
00:08:17,110 --> 00:08:21,460
如果更改了以下数据库服务器的设置,则了解分片
know about the sharding if you change
the setup of the database servers that
93
00:08:21,460 --> 00:08:25,330
您添加了新的数据库服务器,或者您意识到需要拆分密钥
you add a new database server or you
realize you need to split up the keys
94
00:08:25,330 --> 00:08:29,320
不同的是,您知道现在需要一个软件,您将不得不修改该软件
differently you know now you need a
you're gonna have to modify the software
95
00:08:29,320 --> 00:08:33,370
运行在前端或其他东西上,以便他们了解
running on the front ends or something
in order for them to understand about
96
00:08:33,370 --> 00:08:37,750
如何切换到新的分片所以这里有些痛
how to cut over to the new sharding so
there's some there's some pain here
97
00:08:37,750 --> 00:08:42,760
还有是否需要交易,如果您知道很多人会使用它们
there's also if you need transactions
and you know many people use them if you
98
00:08:42,760 --> 00:08:47,140
需要交易,但单笔交易中涉及的数据超过
need transactions but the data involved
in a single transaction is on more than
99
00:08:47,140 --> 00:08:51,730
一台数据库服务器,您可能需要两阶段提交或一些
one database server you're probably
going to need two-phase commit or some
100
00:08:51,730 --> 00:08:59,040
其他分布式交易方案也很痛苦,也很慢
other distributed transaction scheme
it's also a pain and slow all right well
101
00:08:59,040 --> 00:09:07,089
您可以通过这种安排走得很远,但是这很昂贵
you can you can get fairly far with this
arrangement however it's quite expensive
102
00:09:07,089 --> 00:09:12,520
我的续集或你们中的一些人知道功能全面的数据库服务器,例如人
my sequel or sort of you know fully
featured database servers like people
103
00:09:12,520 --> 00:09:18,130
喜欢使用它不是特别快,它可能可以
like to use it's not particularly fast
it can probably
104
00:09:18,130 --> 00:09:24,340
每秒执行数十万次读取,权限大大减少,您
perform a couple hundred thousand reads
per second and far fewer rights and you
105
00:09:24,340 --> 00:09:32,200
知道网站的阅读往往很繁琐,所以很可能您会耗尽
know web sites tend to be read heavy so
it's likely that you're gonna run out of
106
00:09:32,200 --> 00:09:38,410
写入之前先进行读取,流量将是我们在网络上加载的流量
steam for reads before writes that
traffic will be that we load on the web
107
00:09:38,410 --> 00:09:43,660
服务器将由读取为主,因此一段时间后,您就可以切片
servers will be dominated by reads and
so after a while you know you can slice
108
00:09:43,660 --> 00:09:49,210
越来越多的服务器上的数据越来越稀薄,但是有两件事出错了
the data more and more thinly over more
and more servers but two things go wrong
109
00:09:49,210 --> 00:09:54,430
与那个是一些有时你是你有特定的关键是
with that one is that the some sometimes
you're you have specific keys that are
110
00:09:54,430 --> 00:09:59,080
经常使用的热食,没有多少切片的确有帮助,因为每个
hot that are used a lot and no amount of
slicing really helps there because each
111
00:09:59,080 --> 00:10:03,550
密钥仅在单个服务器上,因此非常流行,服务器可以
key is only on a single server so that
keeps very popular that servers can be
112
00:10:03,550 --> 00:10:09,160
无论您对数据进行了多少分区或分片,
overloaded no matter how much you
partition or shard the data and the
113
00:10:09,160 --> 00:10:13,060
添加的另一个问题是缩短添加很多续集
other problem with adding was shorting
adding lots and lots of my sequel
114
00:10:13,060 --> 00:10:20,080
用于分片的数据库服务器的确是一种昂贵的方式
database servers for sharding is that
it's really an expensive way to go as it
115
00:10:20,080 --> 00:10:23,440
事实证明,经过一点之后,您将开始思考得很好
turns out and after a point you're gonna
you're going to start to think that well
116
00:10:23,440 --> 00:10:27,760
而不是花很多钱来添加另一个运行我的数据库服务器
instead of spending a lot of money to
add another database server running my
117
00:10:27,760 --> 00:10:32,920
续集我可以让同一台服务器在它上面运行得更快
sequel I could take the same server run
something much faster on it like as it
118
00:10:32,920 --> 00:10:37,420
发生Memcache D,并且每秒获得更多读取
happens memcache D and get a lot more
reads per second out of the same
119
00:10:37,420 --> 00:10:45,640
使用缓存而不是使用数据库的硬件,因此下一个架构和
Hardware using caching than using
databases so the next architecture and
120
00:10:45,640 --> 00:10:51,940
现在开始与Facebook正在使用的下一个架构相似
this is now starting to resemble what
Facebook is using the next architecture
121
00:10:51,940 --> 00:10:59,950
仍然需要用户,我们仍然有一堆运行Web服务器的前端服务器
still need users we still have a bunch
of front end servers running web servers
122
00:10:59,950 --> 00:11:05,110
在PHP中,到目前为止,也许还有大量的前端服务器,
in PHP and by now maybe a vast number of
front end servers we still have our
123
00:11:05,110 --> 00:11:11,020
数据库服务器,因为您知道我们需要一个可以存储数据的系统
database servers because you know we
need us a system that will store data
124
00:11:11,020 --> 00:11:17,860
为我们安全地存储在磁盘上,我们将为我们提供诸如交易之类的信息
safely on disk for us and we'll provide
things like transactions for us and so
125
00:11:17,860 --> 00:11:21,940
你知道可能想要一个数据库,但是在这两者之间
you know probably want a database for
that but in between we're gonna have a
126
00:11:21,940 --> 00:11:26,160
缓存层就是memcache D进入的地方
caching layer that's this is where
memcache D comes in
127
00:11:26,160 --> 00:11:29,940
当然还有其他可以使用的内容,但memcache
and of course there's other things you
could use that the memcache but memcache
128
00:11:29,940 --> 00:11:34,230
D碰巧是一种非常流行的缓存方案,现在的想法是
D happens to be an extremely popular
caching scheme the idea now is you have
129
00:11:34,230 --> 00:11:41,759
一大堆这些Memcache服务器,以及前端需要读取一些内容时
a whole bunch of these memcache servers
and when a front-end needs to read some
130
00:11:41,759 --> 00:11:47,850
数据首先要做的是询问其中一个Memcache服务器,看您是否拥有
data the first thing it does is ask one
of the memcache servers look do you have
131
00:11:47,850 --> 00:11:50,819
我需要的数据,它将与一些数据一起发送获取请求
the data I need
so it'll send a get request with some
132
00:11:50,819 --> 00:11:56,279
到其中一个Memcache服务器的密钥,Memcache服务器将检查它是否已获得
key to one of the memcache servers and
the memcache server will check it's got
133
00:11:56,279 --> 00:12:00,689
只是内存中的一个表,实际上memcache非常简单,远
just a table in memory it's in fact
memcache is extremely simple it's far
134
00:12:00,689 --> 00:12:07,529
例如,它远比您的实验室3简单得多,但在
far simpler than your lab 3 for example
it just has just as a big hash table on
135
00:12:07,529 --> 00:12:11,040
它使用哈希表中的键检查它是否返回的内存
memory it checks with that keys in the
hash table if it is it sends back the
136
00:12:11,040 --> 00:12:15,180
数据说,是的,这是我兑现的价值,如果我们
data saying oh yeah here's the value
I've cashed for that and if we if the
137
00:12:15,180 --> 00:12:19,319
在此Memcache服务器中的前端命中率很高,然后我可以生成该网页
front end hits in this memcache server
great I can then produce the webpage
138
00:12:19,319 --> 00:12:23,839
如果前端服务器必须在网络服务器中丢失数据,则在其中添加数据
with that data in it if it misses in the
webserver though the front-end has to
139
00:12:23,839 --> 00:12:30,689
然后后方无关的马术数据库服务器,数据库服务器会说
then rear equesticle irrelevant database
server and the database server will say
140
00:12:30,689 --> 00:12:36,779
哦,您知道这是您需要的数据,这时为了
oh you know here's the here's the data
you need and at that point in order to
141
00:12:36,779 --> 00:12:42,540
兑现用于需要它的下一个前端,我们将发送看跌期权
cash it in for the next front-end that
needs it the front end we'll send a put
142
00:12:42,540 --> 00:12:48,300
将数据与数据库一起存储到该Memcache服务器中,因为
with the data it fashion the database
into that memcache server and because
143
00:12:48,300 --> 00:12:52,740
memcache的运行速度至少提高了10倍,也许快了10倍以上
memcache runs at least 10 and maybe
maybe more than 10 times faster for
144
00:12:52,740 --> 00:12:58,079
对于给定的硬件数量,它确实比数据库具有优势
weeds than the database for a given
amount of hardware it really pays off to
145
00:12:58,079 --> 00:13:02,189
对内存缓存和数据库使用相当数量的某些硬件
use a fair amount some of that hardware
for memcache as well as for the database
146
00:13:02,189 --> 00:13:06,420
服务器,所以人们经常使用这种安排,这只会节省它们
servers so people people use this
arrangement a lot and it just saves them
147
00:13:06,420 --> 00:13:12,029
钱是因为内存缓存对于杂草来说要比数据库服务器快得多
money because memcache is so much faster
for weeds than a database server still
148
00:13:12,029 --> 00:13:15,990
需要向数据库发送写操作,因为您希望有权更新
need to send writes to the database
because you want right to an updates to
149
00:13:15,990 --> 00:13:22,379
持久存储在数据库中,因为如果存在
be stored durably on the database as
this can still be there if there's a
150
00:13:22,379 --> 00:13:28,019
崩溃或其他问题,但是您可以将Reese发送到缓存中的次数更多
crash or something but you can send the
Reese to the cache very much more
151
00:13:28,019 --> 00:13:32,639
很快好了,所以我们有一个问题,问题是为什么内存缓存不会
quickly ok so we have a question the
question is why wouldn't the memcache
152
00:13:32,639 --> 00:13:36,329
服务器实际上代表前端命中了put并缓存了响应
server actually hit the put on behalf of
the front-end and cache the response
153
00:13:36,329 --> 00:13:39,209
在响应前端之前,这是一个很好的问题
before responding the front-end so
that's a great question
154
00:13:39,209 --> 00:13:43,439
您可以想象一个缓存层,您将向其发送获取信息,它将
you could imagine a caching layer that
you would send a get to it and it would
155
00:13:43,439 --> 00:13:48,569
如果它错过了memcache层,则会将请求转发给
if it missed the memcache layer would
would forward the request to the
156
00:13:48,569 --> 00:13:52,699
数据库婴儿响应memcache memcache会将数据添加到其
database babies respond the memcache
memcache would add the data to its
157
00:13:52,699 --> 00:13:59,339
表,然后响应,其原因是内存缓存就像一个
tables and then respond and the reason
for this is that memcache is like a
158
00:13:59,339 --> 00:14:02,880
完全不知道的完全独立的软件
completely separate piece of software
that it doesn't know anything about
159
00:14:02,880 --> 00:14:06,509
数据库,实际上甚至不必使用和组合
databases and it's actually not even
necessarily used and combined in
160
00:14:06,509 --> 00:14:12,240
与数据库结合,尽管通常如此,所以我们无法烘烤
conjunction with the database although
it often is so we can't bake in
161
00:14:12,240 --> 00:14:18,480
将数据库存储到内存缓存中的知识以及更深层次的原因是
knowledge of the database into memcache
and sort of deeper reason is that the
162
00:14:18,480 --> 00:14:25,160
前端通常不是真正地在内存缓存中一对一存储数据库记录
front ends are often not really storing
one for one database records in memcache
163
00:14:25,160 --> 00:14:30,899
几乎总是或非常频繁发生的事情是前端
almost always or very frequently what's
going on is that the front-end will
164
00:14:30,899 --> 00:14:35,189
向数据库发出一些请求,然后以某种方式处理结果
issue some requests to the database and
then process the results somewhat you
165
00:14:35,189 --> 00:14:42,949
知道也许要采取一些步骤将其转换为HTML或将其收集在一起
know maybe take a few steps to turning
it into HTML or sort of collect together
166
00:14:42,949 --> 00:14:47,910
您知道数据库中多行上的多个职业的结果,
you know results from multiple careers
on multiple rows in the database and
167
00:14:47,910 --> 00:14:51,120
将部分处理的信息缓存在内存缓存中
cached partially processed information
in memcache