文章列表

Linux 将任务放到后台虚拟终端执行screen命令使用说明

作者:じ☆ve宝贝

我们会经常遇到一些linux系统基础操作比较耗时的任务,比如编译一个大型环境,删除或移动一些文件,又或者是mysql导入一个大型文件比较耗时,如果一个终端执行比较久因为断电退出、超时退出或者误操作,都会导致这些命令终止。又或者我们还需要做一些其他事情,总不能一直等这个操作完成,那么screen就可以完美解决现在的问题了。 简单用法记录如下: 1,新建一个screen。 从linux的ssh终端上直接执行 screen -S abc (abc为给这个终端起的名字,以后可以用到,方便多个screen执行不知道每个是干啥的) 比如我们建立screen -S tongji 这个终端是一个mysql恢复,是一个sql命令导入,过程可能需要一个小时左右。 建立完以后我们就可以关掉这个页面去干其他事情去了。后边只需要进去查看这个操作是否完成就行。 2,查看screen 对于已经建立的screen,我们需要进去查看的时候,需要执行如下操作。 查看screen: ``` root@iZ23gjmzn3tZ:/# screen -ls There are screens on: 10867.mysqldump (08/05/2016 05:09:31 PM) (Detached) 8074.tongji (08/05/2016 09:35:01 AM) (Attached) 2 Sockets in /var/run/screen/S-root. ``` 进入screen -r tongji 或者screen -r 8074 都可以。 ``` root@iZ23gjmzn3tZ:/# screen -r tongji ``` 进入终端显示如下: ``` Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) MySQL [screen_test] ``` 可见这个导入已经恢复完成,我们完全不需要担心中间ssh的这个终端断掉或者是其他方式碰到,后台就给你无人值守执行了。 3,退出一个screen的方法,这里简单总结两个。 方法1:screen -S abc -X quit (abc为当时起的名字) 方法2:screen -r abc 重新激活新的screen,执行exit退出。 更为详细操作,请参考资料: Linux虚拟终端命令Screen用法详解,地址太长,请点击:Screen用法详解 Linux下Screen的常用命令:http://www.linuxidc.com/Linux/2012-07/65358.htm Screen会话命令:http://www.cnblogs.com/ywl925/p/3604530.html

Myeclipse、eclipse安装lombok

作者:じ☆ve宝贝

lombok 注解: lombok 提供的注解不多,可以参考官方视频的讲解和官方文档。 Lombok 注解在线帮助文档:http://projectlombok.org/features/index. 下面介绍几个我常用的 lombok 注解: @Data :注解在类上;提供类所有属性的 getting 和 setting 方法,此外还提供了equals、canEqual、hashCode、toString 方法 @Setter:注解在属性上;为属性提供 setting 方法 @Getter:注解在属性上;为属性提供 getting 方法 @Log4j :注解在类上;为类提供一个 属性名为log 的 log4j 日志对象 @NoArgsConstructor:注解在类上;为类提供一个无参的构造方法 @AllArgsConstructor:注解在类上;为类提供一个全参的构造方法 1、下载地址:https://projectlombok.org/download #### 安装步骤:   1.下载lombok.jar包   2.将lombok.jar包复制到myeclipse.ini/eclipse.ini所在文件目录   3.打开myeclipse.ini/eclipse.ini,在最后添加以下代码并保存:     -javaagent:lombok.jar   4.重启myeclipse/eclipse.   5.project==>clean 清理项目

同样是高并发,QQ/微博/12306的架构难度一样吗?

作者:微信小助手

<section style="line-height: 1.75em;"> <strong><span style="font-size: 15px;letter-spacing: 1px;">开篇</span></strong> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">同一个用户并发扣款时,有一定概率出现数据不一致,<strong>可以使用CAS乐观锁</strong>的方式,在不降低吞吐量,保证数据的一致性:</span> </section> <p style="line-height: normal;"><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">UPDATE t_yue SET money=$new_money<br></span></em></span></p> <p style="line-height: normal;"><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">WHERE uid=$uid AND </span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">money=$old_money</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">;</span></em></span></p> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">更详细的描述,详见《<a href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&amp;mid=2651962738&amp;idx=1&amp;sn=d2d91a380bad06af9f7b9f7a80db26b3&amp;chksm=bd2d08ae8a5a81b8a7f044af52c5e6e77ec3df2bb4a9c91cd450c3fd932e8dade56afb09f784&amp;scene=21#wechat_redirect" target="_blank" data-itemshowtype="0" data-linktype="2">并发扣款,如何保证数据的一致性?</a>》。</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <strong><span style="font-size: 15px;letter-spacing: 1px;">不能采用直接扣减的方式</span></strong> <span style="font-size: 15px;letter-spacing: 1px;">:</span> </section> <p style="line-height: normal;"><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">UPDATE t_yue SET </span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">money=money-$diff</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;"> WHERE uid=$uid;</span></em></span></p> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">更详细的描述,详见《<a href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&amp;mid=2651962770&amp;idx=1&amp;sn=94efc914b0e7d6a74948926a3ea7e9c6&amp;chksm=bd2d084e8a5a8158e7e73d3b917e5189127087a45d78b81ce96db48e6ae2e89cd0bd11c8f301&amp;scene=21#wechat_redirect" target="_blank" data-itemshowtype="0" data-linktype="2">并发扣款一致性,幂等性问题</a>》。</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">当然,更通用的方式,<strong>可以使用版本号</strong>来实现CAS乐观锁:</span> </section> <p style="line-height: normal;"><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">UPDATE t_yue SET money=$new_money,</span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">ver=$ver_new</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;"> <br>WHERE uid=$uid AND </span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">ver=$ver_old</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">;</span></em></span></p> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">更详细的描述,详见《<a href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&amp;mid=2651962761&amp;idx=1&amp;sn=11513a9e34bf77b4545ecdc289f4c8fd&amp;chksm=bd2d08558a5a8143ce15fbd9722fbcc42593b55480ca5eba7b19b2911763bb15bde65e9a2c4b&amp;scene=21#wechat_redirect" target="_blank" data-itemshowtype="0" data-linktype="2">并发扣款一致性优化,CAS下ABA问题</a>》。</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">对于这个CAS乐观锁方案,很有朋友有疑问:</span> <strong><span style="font-size: 15px;letter-spacing: 1px;">当并发量高时,版本号比对会导致大量的更新失败,这个方案不适用于高并发场景吗?</span><span style="font-size: 15px;letter-spacing: 1px;"></span></strong> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">究竟是不是这样呢?</span> <span style="font-size: 15px;letter-spacing: 1px;">大家对高并发是不是有什么误解呢?</span> <span style="font-size: 15px;letter-spacing: 1px;">今天来聊一聊这个话题。<br><br>先分析三个业务场景。</span> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <strong><span style="font-size: 15px;letter-spacing: 1px;">一、QQ</span></strong> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">QQ的一些核心业务有:</span> </section> <ul style="list-style-type: disc;" class=" list-paddingleft-2"> <li><p><span style="font-size: 15px;letter-spacing: 1px;">个人:</span><span style="font-size: 12px;"><em><span style="font-size: 12px;letter-spacing: 1px;">user(</span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">uid</span></em></span><span style="font-size: 12px;"><em><span style="font-size: 12px;letter-spacing: 1px;">, user_info, …)</span></em></span></p></li> <li><p><span style="font-size: 15px;letter-spacing: 1px;">好友:</span><span style="font-size: 12px;"><em><span style="font-size: 12px;letter-spacing: 1px;">user_friends(</span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">uid</span></em></span><span style="font-size: 12px;"><em><span style="font-size: 12px;letter-spacing: 1px;">, friend_id, …)</span></em></span><span style="font-size: 15px;letter-spacing: 1px;"></span></p></li> <li><p><span style="font-size: 15px;letter-spacing: 1px;">加入的群:</span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">user_groups(</span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">uid</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">, group_id, …)</span></em></span><span style="font-size: 15px;letter-spacing: 1px;"></span></p></li> <li><p><span style="font-size: 15px;letter-spacing: 1px;">群:</span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">group(</span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">gid</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">, group_info, …)</span></em></span><span style="font-size: 15px;letter-spacing: 1px;"></span></p></li> <li><p><span style="font-size: 15px;letter-spacing: 1px;">群成员:</span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">group_members(</span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">gid</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">, uid, …)</span></em></span><span style="font-size: 15px;letter-spacing: 1px;"></span></p></li> <li><p><span style="font-size: 15px;letter-spacing: 1px;">个人消息:</span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">msgs_user(</span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">msg_id</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">, uid, …)</span></em></span><span style="font-size: 15px;letter-spacing: 1px;"></span></p></li> <li><p><span style="font-size: 15px;letter-spacing: 1px;">群消息:</span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">msgs_group(</span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">msg_id</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">, gid, …)</span></em></span><span style="font-size: 15px;letter-spacing: 1px;"></span></p></li> </ul> <section style="line-height: 1.75em;"></section> <section style="line-height: 1.75em;"></section> <section style="line-height: 1.75em;"></section> <section style="line-height: 1.75em;"></section> <section style="line-height: 1.75em;"></section> <section style="line-height: 1.75em;"></section> <section style="line-height: 1.75em;"></section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">这些信息的读写有一个特点,都会带上uid/gid/msgid属性。</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">例如,<strong>拉取好友列表</strong>:</span> </section> <p style="line-height: normal;"><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">select friend_id from user_friends where </span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">uid=$uid</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">;</span></em></span><span style="font-size: 15px;letter-spacing: 1px;"></span></p> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">在用户量很大,并发量很大时,</span> <span style="font-size: 15px;letter-spacing: 1px;color: rgb(255, 76, 0);">不同用户/群/消息数据的读写并没有锁冲突</span> <span style="font-size: 15px;letter-spacing: 1px;">。</span> </section> <section style="line-height: 1.75em;"> <span style="color: rgb(0, 82, 255);"><em><span style="font-size: 15px;letter-spacing: 1px;">画外音:</span></em><em><span style="font-size: 15px;letter-spacing: 1px;">10W个用户同时读写,彼此没有锁冲突。</span></em></span> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">只有当,同一个用户,很短的时间内,有大量并发时,才可能存在锁冲突。</span> </section> <section style="line-height: 1.75em;"> <span style="color: rgb(0, 82, 255);"><em><span style="font-size: 15px;letter-spacing: 1px;">画外音:例如,</span></em><em><span style="font-size: 15px;letter-spacing: 1px;">1个用户,1秒钟读写1W次。</span></em></span> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <strong><span style="font-size: 15px;letter-spacing: 1px;">二、微博</span></strong> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">微博的核心业务是feed流:</span> </section> <ul style="list-style-type: disc;" class=" list-paddingleft-2"> <li><p><span style="font-size: 15px;letter-spacing: 1px;"></span><span style="font-size: 15px;letter-spacing: 1px;">发消息,写操作</span></p></li> <li><p><span style="font-size: 15px;letter-spacing: 1px;"></span><span style="font-size: 15px;letter-spacing: 1px;">刷消息,读操作</span></p></li> </ul> <section style="line-height: 1.75em;"></section> <section style="line-height: 1.75em;"></section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">微博业务显然是</span> <span style="font-size: 15px;letter-spacing: 1px;color: rgb(255, 76, 0);">读多写少</span> <span style="font-size: 15px;letter-spacing: 1px;">的,在用户刷消息时,</span> <span style="font-size: 15px;letter-spacing: 1px;color: rgb(255, 76, 0);">自己feed流里的消息,是由别人发出的</span> <span style="font-size: 15px;letter-spacing: 1px;">。</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <strong><span style="font-size: 15px;letter-spacing: 1px;">查看自己主页feed流</span></strong> <span style="font-size: 15px;letter-spacing: 1px;">,最朴素的实现方法是:</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">(1) 拉取自己关注的用户id_list;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">(2) 拉取这些用户最近N条消息;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">(3) 将这N*id_list条消息排序;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">(4) 返回第一页消息,得到自己主页feed流;</span> </section> <section style="line-height: 1.75em;"> <span style="color: rgb(0, 82, 255);"><em><span style="font-size: 15px;letter-spacing: 1px;">画外音:</span></em><em><span style="font-size: 15px;letter-spacing: 1px;">这里不展开读扩散,写扩散,详见《<a href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&amp;mid=2651961939&amp;idx=1&amp;sn=31a0a4b45a25befbde5b05fe0ba574f6&amp;chksm=bd2d0f8f8a5a86994f983eb45873e06145d5ebbafedec9adf039aabef9cef70700b87e0c5aa8&amp;scene=21#wechat_redirect" target="_blank" data-itemshowtype="0" data-linktype="2">读扩散?写扩散?</a>》。</span></em></span> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">在用户量很大,并发量很大时,</span> <span style="font-size: 15px;letter-spacing: 1px;color: rgb(255, 76, 0);">会有一定数据的读写锁冲突</span> <span style="font-size: 15px;letter-spacing: 1px;">。</span> </section> <section style="line-height: 1.75em;"> <span style="color: rgb(0, 82, 255);"><em><span style="font-size: 15px;letter-spacing: 1px;">画外音:</span></em><em><span style="font-size: 15px;letter-spacing: 1px;">不像QQ,基本是读写自己的数据,微博要写自己的数据,读别人的数据。</span></em></span> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <strong><span style="font-size: 15px;letter-spacing: 1px;">三、12306</span></strong> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">12306的核心业务是:</span> </section> <ul style="list-style-type: disc;" class=" list-paddingleft-2"> <li><p><span style="font-size: 15px;letter-spacing: 1px;"></span><span style="font-size: 15px;letter-spacing: 1px;">查票,读操作</span></p></li> <li><p><span style="font-size: 15px;letter-spacing: 1px;"></span><span style="font-size: 15px;letter-spacing: 1px;">买票,</span><span style="font-size: 15px;letter-spacing: 1px;">写操作</span></p></li> </ul> <section style="line-height: 1.75em;"></section> <section style="line-height: 1.75em;"></section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <p style="line-height: normal;"><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">stock(id, num) // 某一列车有多少张余票</span></em></span><span style="font-size: 15px;letter-spacing: 1px;"></span></p> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">在用户量很大,并发量很大时,</span> <span style="font-size: 15px;letter-spacing: 1px;color: rgb(255, 76, 0);">有极大的锁冲突</span> <span style="font-size: 15px;letter-spacing: 1px;">。</span> </section> <section style="line-height: 1.75em;"> <span style="color: rgb(0, 82, 255);"><em><span style="font-size: 15px;letter-spacing: 1px;">画外音:</span></em><em><span style="font-size: 15px;letter-spacing: 1px;">这个业务,数据量并不大。</span></em></span> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">这类“秒杀”业务,如果不做特殊的优化,</span> <span style="font-size: 15px;letter-spacing: 1px;color: rgb(255, 76, 0);">数据库很容易死锁卡死</span> <span style="font-size: 15px;letter-spacing: 1px;">,没有任何人能买票成功。</span> </section> <section style="line-height: 1.75em;"> <span style="color: rgb(0, 82, 255);"><em><span style="font-size: 15px;letter-spacing: 1px;">画外音:</span></em><em><span style="font-size: 15px;letter-spacing: 1px;">要做什么特殊的优化呢?</span></em></span> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <strong><span style="font-size: 15px;letter-spacing: 1px;">收尾</span></strong> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">QQ,微博、12306,同样是高并发业务,就数据存储锁冲突来说,各自的难度,数据不一致的概率是不同的。</span> </section> <section style="line-height: 1.75em;"> <span style="color: rgb(0, 82, 255);"><em><span style="font-size: 15px;letter-spacing: 1px;">画外音:</span></em><em><span style="font-size: 15px;letter-spacing: 1px;">你不能说,QQ不是高并发业务吧。</span></em></span> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">回到开篇,使用CAS乐观锁进库存扣减:</span> </section> <p style="line-height: normal;"><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;"><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">UPDATE t_yue SET money=$new_money,</span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">ver=$ver_new</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;"> <br>WHERE uid=$uid AND </span></em></span><span style="font-size: 12px;color: rgb(255, 76, 0);"><em><span style="font-size: 12px;letter-spacing: 1px;">ver=$ver_old</span></em></span><span style="font-size: 12px;"><em><span style="letter-spacing: 1px;">;</span></em></span></span></em></span><span style="font-size: 15px;letter-spacing: 1px;"></span></p> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;color: rgb(255, 76, 0);">只要有uid这个过滤属性,即使10W用户同时扣款,也不容易出现数据不一致</span> <span style="font-size: 15px;letter-spacing: 1px;">。</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">只有当同一个用户,同一秒钟,有大量扣减时,才有一定几率会冲撞,但也不会导致数据不一致。</span> </section> <section style="line-height: 1.75em;"> <span style="color: rgb(0, 82, 255);"><em><span style="font-size: 15px;letter-spacing: 1px;">画外音:</span></em><em><span style="font-size: 15px;letter-spacing: 1px;">有一位很可爱的水友,说万一PC端和APP端同时下单怎么办。</span></em></span> <span style="font-size: 15px;letter-spacing: 1px;"></span> </section> <section style="line-height: 1.75em;"> <span style="font-size: 15px;letter-spacing: 1px;">&nbsp;</span> </section> <section style="line-height: 1.75em;"> <strong><span style="font-size: 15px;letter-spacing: 1px;">结论</span></strong> <span style="font-size: 15px;letter-spacing: 1px;"><br></span> <span style="font-size: 15px;letter-spacing: 1px;">高并发的扣款场景,可以使用CAS乐观锁,采用select&amp;set方式进行扣款,既能够保证吞吐量,又能够保证一致性。</span> </section> <section style="text-align: center;color: rgb(51, 51, 51);line-height: normal;clear: both;box-sizing: border-box;background-color: rgb(255, 255, 255);"> <span style="margin: 0px;padding: 0px;letter-spacing: 1px;font-size: 15px;word-wrap: break-word;max-width: 100%;box-sizing: border-box;"><strong style="box-sizing: border-box;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;margin-top: 0px;max-width: 100%;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;padding-top: 0px;word-wrap: break-word;"><img style="box-sizing: border-box;margin: 0px;max-width: 677px;padding: 0px;visibility: visible !important;overflow-wrap: break-word;width: 130px !important;height: auto !important;" data-ratio="1" data-type="jpeg" data-w="250" data-s="300,640" class="" src="/upload/7ddc9700032e2c5cee163f1f1a37b46c.jpg" width="auto"></strong></span> </section> <section style="text-align: center;color: rgb(51, 51, 51);line-height: normal;clear: both;box-sizing: border-box;background-color: rgb(255, 255, 255);"> <span style="margin: 0px;padding: 0px;letter-spacing: 1px;font-size: 12px;word-wrap: break-word;max-width: 100%;box-sizing: border-box;"><strong style="box-sizing: border-box;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;margin-top: 0px;max-width: 100%;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;padding-top: 0px;word-wrap: break-word;"><strong style="box-sizing: border-box;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;margin-top: 0px;max-width: 100%;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;padding-top: 0px;word-wrap: break-word;">架构师之路</strong>-分享技术思路</strong><strong style="box-sizing: border-box;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;margin-top: 0px;max-width: 100%;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;padding-top: 0px;word-wrap: break-word;"></strong><br style="box-sizing: border-box;margin-bottom: 0px;margin-left: 0px;margin-right: 0px;margin-top: 0px;max-width: 100%;padding-bottom: 0px;padding-left: 0px;padding-right: 0px;padding-top: 0px;word-wrap: break-word;"></span> </section> <section style="margin: 0px;padding: 0px;text-align: left;color: rgb(51, 51, 51);text-transform: none;line-height: 1.75em;text-indent: 0px;letter-spacing: 0.54px;clear: both;font-size: 17px;font-style: normal;font-variant: normal;font-weight: 400;text-decoration: none;word-spacing: 0px;white-space: normal;word-wrap: break-word;min-height: 17px;max-width: 677px;box-sizing: border-box;orphans: 2;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);"> <span style="margin: 0px;padding: 0px;letter-spacing: 1px;font-size: 15px;word-wrap: break-word;max-width: 100%;box-sizing: border-box;">相关文章:</span> </section> <section style="margin: 0px;padding: 0px;text-align: left;color: rgb(51, 51, 51);text-transform: none;line-height: 1.75em;text-indent: 0px;letter-spacing: 0.54px;clear: both;font-size: 17px;font-style: normal;font-variant: normal;font-weight: 400;text-decoration: none;word-spacing: 0px;white-space: normal;word-wrap: break-word;min-height: 17px;max-width: 677px;box-sizing: border-box;orphans: 2;-webkit-text-stroke-width: 0px;background-color: rgb(255, 255, 255);"> <span style="margin: 0px;padding: 0px;letter-spacing: 1px;font-size: 15px;word-wrap: break-word;max-width: 100%;box-sizing: border-box;">《<a href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&amp;mid=2651962738&amp;idx=1&amp;sn=d2d91a380bad06af9f7b9f7a80db26b3&amp;chksm=bd2d08ae8a5a81b8a7f044af52c5e6e77ec3df2bb4a9c91cd450c3fd932e8dade56afb09f784&amp;scene=21#wechat_redirect" target="_blank" data-linktype="2" data-itemshowtype="0">并发扣款,如何保证数据的一致性?</a>》<br>《<a href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&amp;mid=2651962761&amp;idx=1&amp;sn=11513a9e34bf77b4545ecdc289f4c8fd&amp;chksm=bd2d08558a5a8143ce15fbd9722fbcc42593b55480ca5eba7b19b2911763bb15bde65e9a2c4b&amp;scene=21#wechat_redirect" target="_blank" data-itemshowtype="0" data-linktype="2">并发扣款一致性优化,CAS下ABA问题</a>》<br><span style="font-size: 15px;letter-spacing: 1px;">《<a href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&amp;mid=2651962770&amp;idx=1&amp;sn=94efc914b0e7d6a74948926a3ea7e9c6&amp;chksm=bd2d084e8a5a8158e7e73d3b917e5189127087a45d78b81ce96db48e6ae2e89cd0bd11c8f301&amp;scene=21#wechat_redirect" target="_blank" data-itemshowtype="0" data-linktype="2">并发扣款一致性,幂等性问题</a>》<br>《<a href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&amp;mid=2651961939&amp;idx=1&amp;sn=31a0a4b45a25befbde5b05fe0ba574f6&amp;chksm=bd2d0f8f8a5a86994f983eb45873e06145d5ebbafedec9adf039aabef9cef70700b87e0c5aa8&amp;scene=21#wechat_redirect" target="_blank" data-itemshowtype="0" data-linktype="2">读扩散?写扩散?</a>》</span></span> <br> </section> <p><span style="text-align: justify;color: rgb(51, 51, 51);text-transform: none;text-indent: 0px;letter-spacing: 1px;font-family: &quot;mp-quote&quot;,-apple-system-font,BlinkMacSystemFont,&quot;Helvetica Neue&quot;,&quot;PingFang SC&quot;,&quot;Hiragino Sans GB&quot;,&quot;Microsoft YaHei UI&quot;,&quot;Microsoft YaHei&quot;,Arial,sans-serif;font-size: 15px;font-style: normal;font-variant: normal;font-weight: 400;text-decoration: none;word-spacing: 0px;display: inline !important;orphans: 2;float: none;-webkit-text-stroke-width: 0px;background-color: transparent;"><br></span></p> <p><span style="text-align: justify;color: rgb(51, 51, 51);text-transform: none;text-indent: 0px;letter-spacing: 1px;font-family: &quot;mp-quote&quot;,-apple-system-font,BlinkMacSystemFont,&quot;Helvetica Neue&quot;,&quot;PingFang SC&quot;,&quot;Hiragino Sans GB&quot;,&quot;Microsoft YaHei UI&quot;,&quot;Microsoft YaHei&quot;,Arial,sans-serif;font-size: 15px;font-style: normal;font-variant: normal;font-weight: 400;text-decoration: none;word-spacing: 0px;display: inline !important;orphans: 2;float: none;-webkit-text-stroke-width: 0px;background-color: transparent;">任何脱离业务的架构设计,都是耍流氓</span><span style="text-align: justify;color: rgb(51, 51, 51);text-transform: none;text-indent: 0px;letter-spacing: 1px;font-family: &quot;mp-quote&quot;,-apple-system-font,BlinkMacSystemFont,&quot;Helvetica Neue&quot;,&quot;PingFang SC&quot;,&quot;Hiragino Sans GB&quot;,&quot;Microsoft YaHei UI&quot;,&quot;Microsoft YaHei&quot;,Arial,sans-serif;font-size: 15px;font-style: normal;font-variant: normal;font-weight: 400;text-decoration: none;word-spacing: 0px;display: inline !important;orphans: 2;float: none;-webkit-text-stroke-width: 0px;background-color: transparent;">。</span></p>

一文搞懂面试必备的分布式事物方案

作者:微信小助手

<section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <section style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;box-sizing: border-box;transform: translate3d(0px, 0px, 0px);text-align: center;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;display: inline-block;vertical-align: middle;width: 406.188px;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <section style="box-sizing: border-box;font-size: 16px;"> <section style="box-sizing: border-box;" powered-by="xiumi.us"> <section style="transform: translate3d(0px, 0px, 0px);-webkit-transform: translate3d(0px, 0px, 0px);-moz-transform: translate3d(0px, 0px, 0px);-o-transform: translate3d(0px, 0px, 0px);text-align: center;margin: 10px 0%;box-sizing: border-box;"> <section style="display: inline-block;vertical-align: middle;width: 60%;box-sizing: border-box;"> <section style="box-sizing: border-box;" powered-by="xiumi.us"> <p style="text-align: center;"><br></p> <p style="text-align: center;"><br></p> </section> </section> <section style="display: inline-block;vertical-align: middle;width: 12%;border-left: 1px solid rgb(209, 222, 203);border-bottom-left-radius: 0px;border-right: 1px solid rgb(209, 222, 203);border-top-right-radius: 0px;border-top-width: 0px;box-sizing: border-box;"> <section style="box-sizing: border-box;" powered-by="xiumi.us"> <section style="box-sizing: border-box;"> <section style="color: rgb(173, 158, 159);box-sizing: border-box;"> <p style="box-sizing: border-box;"><strong style="box-sizing: border-box;"></strong></p> </section> </section> </section> </section> </section> </section> </section> <section style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <span style="font-size: 14px;background-color: rgb(255, 255, 255);letter-spacing: 0.544px;color: rgb(15, 15, 15);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">本文转载自公众号:Java极客技术,作者:乔二爷<br></span> </section> <section style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"></section> <section style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"></section> <section style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <span style="font-size: 14px;background-color: rgb(255, 255, 255);letter-spacing: 0.544px;color: rgb(15, 15, 15);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">公众号后台回复“</span> <span style="font-size: 14px;background-color: rgb(255, 255, 255);letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;max-width: 100%;box-sizing: border-box;color: rgb(255, 76, 0);overflow-wrap: break-word !important;">面试突击</span> <span style="font-size: 14px;background-color: rgb(255, 255, 255);letter-spacing: 0.544px;color: rgb(15, 15, 15);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">”,获得Java面试突击第三版!</span> <br> </section> </section> </section> </section> </section> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;font-size: 14px;text-align: center;line-height: 1.8;color: rgb(15, 15, 15);overflow-wrap: break-word !important;"> <hr style="border-style: solid;border-width: 1px 0 0;border-color: rgba(0,0,0,0.1);-webkit-transform-origin: 0 0;-webkit-transform: scale(1, 0.5);transform-origin: 0 0;transform: scale(1, 0.5);"> <p style="max-width: 100%;box-sizing: border-box;min-height: 1em;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);overflow-wrap: break-word !important;"><span style="font-size: 14px;"></span><br></p> <p style="max-width: 100%;box-sizing: border-box;min-height: 1em;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);overflow-wrap: break-word !important;text-align: center;"><span style="font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;font-size: 16px;text-align: left;color: rgb(136, 136, 136);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">4月初在面试一家互联网公司的过程中就被问到了分布式事物问题。</span></strong></span></strong><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">我又一次在没有好好整理的问题上吃了亏。记录一下!!!</span></strong></span></strong></span></p> <p style="max-width: 100%;box-sizing: border-box;min-height: 1em;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);overflow-wrap: break-word !important;text-align: center;"><strong style="color: rgb(136, 136, 136);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;font-size: 16px;text-align: left;letter-spacing: 0.544px;"><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br></span></strong></span></strong></p> </section> </section> </section> <p style="box-sizing: border-box;margin: 10px;font-size: 16px;white-space: normal;text-align: center;color: rgb(63, 63, 63);line-height: 1.6;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;"><span style="color: rgb(136, 136, 136);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">背景</span></strong></span></strong></span><span style="text-align: center;font-size: 14px;"></span></p> <p style="box-sizing: border-box;margin: 10px;font-size: 16px;white-space: normal;text-align: center;color: rgb(63, 63, 63);line-height: 1.6;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;"><span style="color: rgb(136, 136, 136);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br></span></strong></span></strong></span></p> <p style="box-sizing: border-box;margin: 10px;font-size: 16px;white-space: normal;text-align: left;color: rgb(63, 63, 63);line-height: 1.6;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;"><span style="color: rgb(136, 136, 136);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">四月初,去面试了本市的一家之前在做办公室无人货架的公司,虽然他们现在在面临着转型,但是对于我这种想从传统企业往互联网行业走的孩子来说,还是比较有吸引力的。</span></strong></span></strong></span></p> <p style="box-sizing: border-box;margin: 10px;font-size: 16px;white-space: normal;text-align: left;color: rgb(63, 63, 63);line-height: 1.6;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;"><span style="color: rgb(136, 136, 136);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">在面试过程中就提到了分布式事物问题。</span></strong></span></strong></span><span style="color: rgb(136, 136, 136);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">我又一次在没有好好整理的问题上吃了亏,记录一下,还是</span></strong></span></strong></span><span style="color: rgb(255, 76, 0);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">长记性 !</span></strong></span></strong></span><span style="color: rgb(255, 76, 0);"><strong><span style="color: rgb(255, 76, 0);font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="color: rgb(255, 76, 0);max-width: 100%;font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">!</span></strong></span></strong></span><span style="color: rgb(255, 76, 0);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">!</span></strong></span></strong></span></p> <p style="box-sizing: border-box;margin: 10px;font-size: 16px;white-space: normal;text-align: left;color: rgb(63, 63, 63);line-height: 1.6;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;"><strong style="color: rgb(136, 136, 136);font-size: 22.4px;"><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;">先看面试过程</span></strong></span></strong></p> <p style="box-sizing: border-box;margin: 10px;font-size: 16px;white-space: normal;text-align: left;color: rgb(63, 63, 63);line-height: 1.6;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;"><span style="color: rgb(136, 136, 136);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">面试官先是在纸上先画了这样一张图:</span></strong></span></strong></span></p> <p style="text-align: center;"><img class="rich_pages" data-copyright="0" data-ratio="0.3650485436893204" data-s="300,640" src="/upload/a865aa7593993a635cb89281f78963dd.png" data-type="png" data-w="1030" style=""></p> <p style="box-sizing: border-box;margin: 10px;font-size: 16px;white-space: normal;text-align: left;color: rgb(63, 63, 63);line-height: 1.6;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;"><span style="color: rgb(136, 136, 136);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">让我看这张图按照上面的流程走,有没有什么问题?</span></strong></span></strong></span><span style="color: rgb(136, 136, 136);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">面试官并没有直接说出来这里面会有分布式事物的问题,而是让我来告诉他,这就是</span></strong></span></strong></span><span style="color: rgb(255, 76, 0);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">面试套路</span></strong></span></strong></span><span style="color: rgb(136, 136, 136);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">呀。</span></strong></span></strong></span><br></p> <p style="box-sizing: border-box;margin: 10px;font-size: 16px;white-space: normal;text-align: left;color: rgb(63, 63, 63);line-height: 1.6;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;"><span style="color: rgb(136, 136, 136);"><strong><span style="font-size: 14px;"><strong style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(85, 85, 85);font-family: Lato, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">我回答了这中间可能存在分布式事物的问题,当步骤2在调用 B 系统时,可能存在B 系统处理完成后,在响应的时

[dubbo]Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'问题解决方法

作者:じ☆ve宝贝

1.我们打开dubbo的jar包,我们可以在META-INF下看到dubbo.xsd 虽然启动没有问题,但xml验证Failed to read schema document 可以通过eclipse 手动添加schema文件来解决这个问题,如图: ![dubbo](/upload/dubbo.png "dubbo") 保存。。在xml文件右键validate ok解决了。

微视无水印下载Java源码

作者:じ☆ve宝贝

## 微视无水印下载Java源码 > 前段时间给大家分享的了抖音无水印下载的Java源码,近日有时间,抓了一下微视的无水印地址,让大家可以享受高清无水印原视频。 ## pom.xml ``` <dependency> <groupId>com.jfinal</groupId> <artifactId>jfinal</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.47</version> </dependency> ``` ## 解析url ``` package cn.studyjava.weishi; /** * Hello world! * */ public class App { public static void main(String[] args) { //@喵大仙带你停药带你菲:‘才华’的重要性 >>https://h5.qzone.qq.com/weishi/feed/XnRuSSdlBeNy01db/wsfeed?_proxy=1&_wv=1&id=XnRuSSdlBeNy01db String wsId = "XnRuSSdlBeNy01db"; String post = HttpKit.post("https://h5.qzone.qq.com/webapp/json/weishi/WSH5GetPlayPage?t=0.4185745904612037&g_tk=", "feedid="+wsId+""); JSONObject res = JSON.parseObject(post); if(0 == res.getIntValue("ret")){ JSONObject data = res.getJSONObject("data"); JSONArray feeds = data.getJSONArray("feeds"); JSONObject feed = feeds.getJSONObject(0); map.put("code", "0"); map.put("msg", "ok"); map.put("url", feed.getString("video_url")); }else{ map.put("code", "1"); map.put("msg", res.getString("msg")); } System.out.println(map.get("url")); } } ``` ## [抖音、微视无水印在线下载](https://www.studyjava.cn/douyin) ## 抖音、微视无水印在线下载(小程序,可以直接保存到相册哦) ![](/upload/762fd13b77664616808c3983a9896b5a.jpg)

Eclipse使用ssh连接gitlab

作者:じ☆ve宝贝

## 1.生成ssh需要的key ![eclipse使用ssh连接gitlab](/upload/510df12e787f4096aa4bf29bbeeedf91.png "eclipse使用ssh连接gitlab") 保存文件是两个,一个id_rsa是私钥,另一个id_rsa.pub是公钥。(该处需要记录文件保存的路径) ## 2.拷贝公钥到服务器 根据上面保存的路径打开id_rsa.pub,拷贝当中的内容打开gitlab ![eclipse使用ssh连接gitlab](/upload/c40c2b20a52547848a0061c844dce262.png) ## 3.将id_rsa.pub公钥内容粘贴到此处 ![eclipse使用ssh连接gitlab](/upload/cc21aae5f1754e4bb817381f456cc059.png) ## 4.拷贝项目地址 ![](/upload/a3b7eb8a8edf4c8dbd2eb5df56f48241.png) ## 5.使用eclipse下载gitlab项目 ![eclipse下载gitlab项目](/upload/38dd84c76dc5442ebf3d332be95652d5.png) ## 6.下载 ![](/upload/34c06ae66431461686897c2930450f42.png) 一直next后选择文件保存目录finish后就好了 ** 问题:有时会出现生成的key文件不能正常使用,在连接服务时会问几次密码后中断,可以尝试重启eclipse**

Java设计模式(转)——15.观察者模式

作者:じ☆ve宝贝

## 15.观察者模式(Observer) 包括这个模式在内的接下来的四个模式,都是类和类之间的关系,不涉及到继承,学的时候应该记得归纳。观察者模式很好理解,类似于邮件订阅和RSS订阅,当我们浏览一些博客或wiki时,经常会看到RSS图标,就这的意思是,当你订阅了该文章,如果后续有更新,会及时通知你。其实,简单来讲就一句话:当一个对象变化时,其它依赖该对象的对象都会收到通知,并且随着变化!对象之间是一种一对多的关系。先来看看关系图: ![观察者设计模式](/upload/content26.png "观察者设计模式") 我解释下这些类的作用:MySubject类就是我们的主对象,Observer1和Observer2是依赖于MySubject的对象,当MySubject变化时,Observer1和Observer2必然变化。AbstractSubject类中定义着需要监控的对象列表,可以对其进行修改:增加或删除被监控对象,且当MySubject变化时,负责通知在列表内存在的对象。我们看实现代码: 一个Observer接口: ``` public interface Observer { public void update(); } ``` 两个实现类: ``` public class Observer1 implements Observer { @Override public void update() { System.out.println("observer1 has received!"); } } ``` ``` public class Observer2 implements Observer { @Override public void update() { System.out.println("observer2 has received!"); } } ``` Subject接口及实现类: ``` public interface Subject { /*增加观察者*/ public void add(Observer observer); /*删除观察者*/ public void del(Observer observer); /*通知所有的观察者*/ public void notifyObservers(); /*自身的操作*/ public void operation(); } ``` ``` public abstract class AbstractSubject implements Subject { private Vector<Observer> vector = new Vector<Observer>(); @Override public void add(Observer observer) { vector.add(observer); } @Override public void del(Observer observer) { vector.remove(observer); } @Override public void notifyObservers() { Enumeration<Observer> enumo = vector.elements(); while(enumo.hasMoreElements()){ enumo.nextElement().update(); } } } ``` ``` public class MySubject extends AbstractSubject { @Override public void operation() { System.out.println("update self!"); notifyObservers(); } } ``` 测试类: ``` public class ObserverTest { public static void main(String[] args) { Subject sub = new MySubject(); sub.add(new Observer1()); sub.add(new Observer2()); sub.operation(); } } ``` 输出: update self! observer1 has received! observer2 has received! 这些东西,其实不难,只是有些抽象,不太容易整体理解,建议读者:根据关系图,新建项目,自己写代码(或者参考我的代码),按照总体思路走一遍,这样才能体会它的思想,理解起来容易!

Google BigTable到底解决什么问题?

作者:微信小助手

<blockquote> <p><span style="color: rgb(178, 178, 178);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 14px;letter-spacing: 1px;text-align: justify;background-color: rgb(255, 255, 255);">搞架构的人,Google的论文是必看的,但好像大家都不愿意去啃英文论文。故把自己的读书笔记,加入自己的思考,分享给大家。</span></p> </blockquote> <p><span style="font-size: 14px;letter-spacing: 1px;"><br></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">第三部分,Google BigTable。</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;"><br></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">BigTable,很多人对它耳熟能详,但它究竟解决什么问题呢?这是今天要聊的话题。</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><strong><span style="font-size: 14px;letter-spacing: 1px;">什么是BigTable?</span></strong></p> <p><span style="font-size: 14px;letter-spacing: 1px;">Google BigTable是一个分布式,结构化数据的</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">存储系统</span><span style="font-size: 14px;letter-spacing: 1px;">,它用来存储海量数据。该系统用来满足“</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">大数据量、高吞吐量、快速响应</span><span style="font-size: 14px;letter-spacing: 1px;">”等不同应用场景下的存储需求。</span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:本质上,BigTable是一个存储系统。</span></em></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><strong><span style="font-size: 14px;letter-spacing: 1px;">有BigTable之前,Google面临什么问题?</span></strong></p> <p><span style="font-size: 14px;letter-spacing: 1px;">Google并不是一群人坐在办公室开会,想出来的系统,Google面临着很实际的业务问题。</span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">很多公司的基础架构部,是坐在办公室开会,想出来的东西,然后强推业务线使用;</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">脱离业务的技术,都是耍流氓。</span></em></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><strong><span style="font-size: 14px;letter-spacing: 1px;">典型场景一:网页存储</span></strong></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">Google每天要抓取很多网页:</span></p> <ul class=" list-paddingleft-2" style="list-style-type: disc;"> <li><p><span style="font-size: 14px;letter-spacing: 1px;">新出现的网页,<strong>新URL</strong></span></p></li> <li><p><span style="font-size: 14px;letter-spacing: 1px;">旧网页,<strong>旧URL</strong></span></p></li> </ul> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><strong><span style="font-size: 14px;letter-spacing: 1px;">对一个已抓取的网页,旧URL为啥要反复抓取?</span></strong></p> <p><span style="font-size: 14px;letter-spacing: 1px;">因为,</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">网页会更新</span><span style="font-size: 14px;letter-spacing: 1px;">,例如新浪首页:</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">sina.com.cn/index.html</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">URL虽然没有变,但依然会抓取。</span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:我去,相当于,被抓取的URL集合,只会无限增大,趋近无穷,这里面的技术难题,不知道大家感不感兴趣?</span></em></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">这里,对于<strong>存储系统的需求</strong>,是要存储:</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">不同URL,不同时间Time,的内容Content</span><span style="font-size: 14px;letter-spacing: 1px;">。</span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:URL+”Content”+Time =&gt; Binary。</span></em></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">网页的实际内容Binary,是Spider抓取出来的。</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><strong><span style="font-size: 14px;letter-spacing: 1px;">典型场景二:Google Analytics</span></strong></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">Google Analytics要给站长展示其网站的流量PV,独立用户数UV,典型访问路径等,以帮助站长了解站点情况,优化站点。</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">这里,对于<strong>存储系统的需求</strong>,是要存储,</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">不同URL,不同时间Time,的PV和UV</span><span style="font-size: 14px;letter-spacing: 1px;">。</span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">URL+”PV”+Time =&gt; $count</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">URL+”UV”+Time =&gt; $count</span></em></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">PV和UV的值,是MapReduce离线任务计算出来的。</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">不管是“网页存储”还是“站点统计”存储,它们都有几个共同的特点:</span></p> <ul class=" list-paddingleft-2" style="list-style-type: disc;"> <li><p><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">数据量极大</span><span style="font-size: 14px;letter-spacing: 1px;">,TB,PB级别</span></p></li> <li><p><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">和时间维度相关</span></p></li> <li><p><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">同一个主键,属性与值有映射</span></p></li> </ul> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">主键是URL,属性是“Content”,值是网页Binary;</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">主键是URL,属性是“PV”和“UV”,值是计数count。</span></em></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">这是Google曾经遇到的难题,面对这些难题,典型的解决方案又有哪些呢?</span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:不是一上来就搞新方案,最先肯定是想用现有的技术要如何解决。</span></em></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><strong><span style="font-size: 14px;letter-spacing: 1px;">最容易想到的主键,属性,值的存储系统是什么?</span></strong></p> <p><span style="font-size: 14px;letter-spacing: 1px;">没错,就是关系型数据库:</span></p> <p style="text-align: left;"><img class="" data-copyright="0" data-ratio="0.2814814814814815" data-s="300,640" src="/upload/2b52e8b6b68b5cc519b59709027b4d72.jpg" data-type="jpeg" data-w="405" style=""></p> <p><span style="font-size: 14px;letter-spacing: 1px;">如上图所示,用户表</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">User(uid </span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">PK</span><span style="font-size: 14px;letter-spacing: 1px;">, name, gender, age, sex)</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">就是一个典型的主键,属性,值的存储模型:</span></p> <ul class=" list-paddingleft-2" style="list-style-type: disc;"> <li><p><strong><span style="font-size: 14px;letter-spacing: 1px;">主键</span></strong><span style="font-size: 14px;letter-spacing: 1px;">,不同用户的uid</span></p></li> <li><p><strong><span style="font-size: 14px;letter-spacing: 1px;">属性</span></strong><span style="font-size: 14px;letter-spacing: 1px;">,schema的列名</span></p></li> <li><p><strong><span style="font-size: 14px;letter-spacing: 1px;">值</span></strong><span style="font-size: 14px;letter-spacing: 1px;">,不同主键的各个列名,对应的值</span></p></li> </ul> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">使用excel来举例是很直观的,这是一个</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">二维table</span><span style="font-size: 14px;letter-spacing: 1px;">。</span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:屎黄色的主键是一个维度,橙色的属性是一个维度。</span></em></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><strong><span style="font-size: 14px;letter-spacing: 1px;">用二维table能不能解决Google网页存储的问题呢?</span></strong></p> <p style="text-align: left;"><img class="" data-copyright="0" data-ratio="0.2839506172839506" data-s="300,640" src="/upload/e1c43656fae20278f8199df8b4854dc3.jpg" data-type="jpeg" data-w="405" style=""></p> <p><span style="font-size: 14px;letter-spacing: 1px;">如上图所示,</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">如果没有时间维度Time,似乎是可以</span><span style="font-size: 14px;letter-spacing: 1px;">的:</span></p> <ul class=" list-paddingleft-2" style="list-style-type: disc;"> <li><p><strong><span style="font-size: 14px;letter-spacing: 1px;">主键</span></strong><span style="font-size: 14px;letter-spacing: 1px;">,使用URL</span></p></li> <li><p><strong><span style="font-size: 14px;letter-spacing: 1px;">属性</span></strong><span style="font-size: 14px;letter-spacing: 1px;">,schema的列名,例如content,author等</span></p></li> <li><p><strong><span style="font-size: 14px;letter-spacing: 1px;">值</span></strong><span style="font-size: 14px;letter-spacing: 1px;">,不同URL的内容与作者等值</span></p></li> </ul> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">但是,一旦加入时间维度Time,二维table似乎就不灵了。</span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">增加一个time属性是没有用的;</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">增加一个time属性,只能记录同一个URL,某一个time的content,不能记录多个time的多个content;</span></em></span></p> <p><span style="color:#0052ff;"><span style="font-size: 14px;letter-spacing: 1px;"><em>增加一个time属性,联合主键,URL就不是KEY了;</em></span></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><strong><span style="font-size: 14px;letter-spacing: 1px;">能不能用二维table存储三维数据呢?</span></strong></p> <p><span style="font-size: 14px;letter-spacing: 1px;">似乎可以通过trick的手段,在key上做文章,</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">用key+time来拼接新key</span><span style="font-size: 14px;letter-spacing: 1px;">来实现。</span></p> <p style="text-align: left;"><img class="" data-copyright="0" data-ratio="0.7160493827160493" data-s="300,640" src="/upload/c6be2a31f8fd3e9c4b12c312fb54fd71.jpg" data-type="jpeg" data-w="405" style=""></p> <p><span style="font-size: 14px;letter-spacing: 1px;">如上图所示,仍然是二维table,通过URL+Time来瓶装key,也能够实现,存储同一个URL,在不同Time,的不同content、author。</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">但是,这种trick方案存在的问题是:</span></p> <ul class=" list-paddingleft-2" style="list-style-type: disc;"> <li><p><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">没法实现URL查询</span></p></li> </ul> <p><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);"><span style="color: rgb(0, 82, 255);font-size: 14px;font-style: italic;letter-spacing: 1px;">画外音:</span><span style="color: rgb(0, 82, 255);font-size: 14px;font-style: italic;letter-spacing: 1px;">key上无法进行%like%查询。</span></span></p> <ul class=" list-paddingleft-2" style="list-style-type: disc;"> <li><p><span style="font-size: 14px;letter-spacing: 1px;">大量空洞,浪费存储空间</span></p></li> </ul> <p><span style="font-size: 14px;letter-spacing: 1px;">这并不是一个好的方案。</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">况且,当数据量达到TB、PB级别时,传统单机关系型数据库,根本无法满足Google的业务需求。</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><strong><span style="font-size: 14px;letter-spacing: 1px;">BigTable解决什么问题?</span></strong></p> <p><span style="font-size: 14px;letter-spacing: 1px;">传统二维small table,无法解决Google面临的存储问题,于是Google搞了一个big table来解决。</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">Google对这些业务模型进行分析,在二维table的基础上扩充,抽象了一个新的“</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">三维table</span><span style="font-size: 14px;letter-spacing: 1px;">”:</span></p> <ul class=" list-paddingleft-2" style="list-style-type: disc;"> <li><p><strong><span style="font-size: 14px;letter-spacing: 1px;">主键</span></strong><span style="font-size: 14px;letter-spacing: 1px;">,使用URL</span></p></li> <li><p><strong><span style="font-size: 14px;letter-spacing: 1px;">属性</span></strong><span style="font-size: 14px;letter-spacing: 1px;">,schema的列名,例如content,author等</span></p></li> <li><p><strong><span style="font-size: 14px;letter-spacing: 1px;">时间</span></strong><span style="font-size: 14px;letter-spacing: 1px;">,timestamp</span></p></li> <li><p><strong><span style="font-size: 14px;letter-spacing: 1px;">值</span></strong><span style="font-size: 14px;letter-spacing: 1px;">,不同URL的内容与作者等值</span></p></li> </ul> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p style="text-align: left;"><img class="" data-copyright="0" data-ratio="0.6935779816513762" data-s="300,640" src="/upload/6816070ca5062fa062484c5186baacd7.jpg" data-type="jpeg" data-w="545" style=""></p> <p><span style="font-size: 14px;letter-spacing: 1px;">如上图所示:</span></p> <ul class=" list-paddingleft-2" style="list-style-type: disc;"> <li><p><span style="font-size: 14px;letter-spacing: 1px;">第一维:key(屎黄色)</span></p></li> <li><p><span style="font-size: 14px;letter-spacing: 1px;">第二维:属性(橙色)</span></p></li> <li><p><span style="font-size: 14px;letter-spacing: 1px;">第三维:time(蓝色)</span></p></li> </ul> <p><span style="font-size: 14px;letter-spacing: 1px;">同一个key,不同属性,不同时间,会存储一个value。</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">不像</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">以行为单位</span><span style="font-size: 14px;letter-spacing: 1px;">进行存储的传统关系型数据库,这个三维的大表格BigTable是一个稀疏</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">列存储</span><span style="font-size: 14px;letter-spacing: 1px;">系统。</span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:能够压缩空间。</span></em></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">它的</span><span style="letter-spacing: 1px;font-size: 18px;"><strong>数据模型</strong></span><span style="font-size: 14px;letter-spacing: 1px;">的本质是一个</span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">map</span><span style="font-size: 14px;letter-spacing: 1px;">:</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">key + column + time =&gt; value</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">的一个超级大map。</span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">很多业务符合这一个模型;</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">Google的东西能解决业务问题,所以用的人多,这一点很重要。</span></em></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><strong><span style="font-size: 14px;letter-spacing: 1px;">总结</span></strong></p> <p><span style="font-size: 14px;letter-spacing: 1px;">BigTable是一个<strong>稀疏的</strong>、<strong>分布式的</strong>、<strong>持久化的</strong>、<strong>多维度排序的</strong>、<strong>大数据量</strong></span><span style="font-size: 14px;letter-spacing: 1px;color: rgb(255, 76, 0);">存储系统</span><span style="font-size: 14px;letter-spacing: 1px;">,它能够解决符合上述map数据模型业务的存储问题。</span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="font-size: 14px;letter-spacing: 1px;">画外音:</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">GFS是文件系统;</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">MapReduce是计算模型;</span></em></span></p> <p><span style="color: rgb(0, 82, 255);"><em><span style="color: rgb(0, 82, 255);font-size: 14px;letter-spacing: 1px;">BigTable是存储系统。</span></em></span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">BigTable是啥,解决啥问题,这次终于懂了。</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">&nbsp;</span></p> <p><span style="font-size: 14px;letter-spacing: 1px;">很多时候,<strong>定义清楚问题比解决问题更难</strong>。</span></p> <p style="max-width: 100%;min-height: 1em;color: rgb(51, 51, 51);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 17px;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: center;line-height: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><img width="auto" data-ratio="1" data-w="250" data-type="jpeg" data-s="300,640" class="" src="/upload/7ddc9700032e2c5cee163f1f1a37b46c.jpg" style="max-width: 677px;box-sizing: border-box;word-wrap: break-word;visibility: visible !important;width: 130px !important;"></p> <p style="max-width: 100%;min-height: 1em;color: rgb(51, 51, 51);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 17px;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: center;line-height: normal;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 1px;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 12px;">架构师之路-分享</span><span style="max-width: 100%;font-size: 12px;color: rgb(255, 76, 0);">可落地</span><span style="max-width: 100%;font-size: 12px;">的技术文章</span></span></p> <p style="max-width: 100%;min-height: 1em;color: rgb(51, 51, 51);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 17px;letter-spacing: 0.544px;text-align: justify;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;"></p> <p style="max-width: 100%;min-height: 1em;color: rgb(51, 51, 51);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 17px;letter-spacing: 0.544px;text-align: justify;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 14px;letter-spacing: 1px;box-sizing: border-box !important;word-wrap: break-word !important;">相关推荐:</span></p> <p style="max-width: 100%;min-height: 1em;color: rgb(51, 51, 51);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 17px;letter-spacing: 0.544px;text-align: justify;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 14px;letter-spacing: 1px;box-sizing: border-box !important;word-wrap: break-word !important;">《<a href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&amp;mid=2651961812&amp;idx=1&amp;sn=592e3cc722bdfc4201d07cb1b087ed06&amp;chksm=bd2d0c088a5a851eec1e01cea1d68a365edab46bc6985c469adb4b0df17f0e6c2f07bda8da47&amp;scene=21#wechat_redirect" target="_blank" style="color: rgb(87, 107, 149);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;">Google FileSystem架构启示</a>》</span></p> <p style="max-width: 100%;min-height: 1em;color: rgb(51, 51, 51);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 17px;letter-spacing: 0.544px;text-align: justify;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 14px;letter-spacing: 1px;box-sizing: border-box !important;word-wrap: break-word !important;">《<a href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&amp;mid=2651961826&amp;idx=1&amp;sn=98f6ec5271c7a4153c3e50c7b8be4f33&amp;chksm=bd2d0c3e8a5a8528177b34db26876e510486c78f331bd5e51082a22eda9d65b9bfc35abe1c53&amp;scene=21#wechat_redirect" target="_blank" style="color: rgb(87, 107, 149);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;">Google MapReduce解决什么问题?</a>》</span></p> <p style="max-width: 100%;min-height: 1em;color: rgb(51, 51, 51);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 17px;letter-spacing: 0.544px;text-align: justify;white-space: normal;background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;font-size: 14px;letter-spacing: 1px;box-sizing: border-box !important;word-wrap: break-word !important;">《<a href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&amp;mid=2651961881&amp;idx=1&amp;sn=a417acab437b7dea6a7ce6b5b9b31bfa&amp;chksm=bd2d0fc58a5a86d30462ab461443683e164425136ba8169efb4cd9ea95e79bff74d3f25fdf0e&amp;scene=21#wechat_redirect" target="_blank" style="color: rgb(87, 107, 149);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;">MapReduce,颠覆了分层架构的本质?</a>》</span></p>

Elasticsearch如何做到亿级数据查询毫秒级返回?

作者:微信小助手

<section style="box-sizing: border-box;font-size: 16px;"> <section style="box-sizing: border-box;" powered-by="xiumi.us"> <section style="margin-top: 10px;margin-bottom: 10px;box-sizing: border-box;"> <section style="padding-top: 10px;padding-right: 10px;padding-left: 10px;box-sizing: border-box;background-color: rgb(239, 239, 239);"> <span style="display: inline-block;width: 5%;line-height: 0.8;font-weight: bolder;font-size: 48px;box-sizing: border-box;"> <section style="box-sizing: border-box;"> “ </section></span> <section style="display: inline-block;vertical-align: top;float: right;width: 90%;line-height: 1.5;font-size: 15px;color: rgb(89, 89, 89);box-sizing: border-box;"> <p style="box-sizing: border-box;"><span style="letter-spacing: 1px;">如果面试的时候碰到这样一个面试题:ES 在数据量很大的情况下(数十亿级别)如何提高查询效率?</span></p> </section> <section style="clear: both;box-sizing: border-box;"></section> </section> </section> </section> </section> <p style="line-height: 1.75em;"><br></p> <p style="text-align: center;margin-left: 8px;margin-right: 8px;"><img class="rich_pages" data-copyright="0" data-ratio="0.48205928237129486" data-s="300,640" src="/upload/413de884be844596fd2c43f3193fb1e3.png" data-type="png" data-w="641" style=""></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">这个问题说白了,就是看你有没有实际用过 ES,因为啥?</span><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">其实 ES 性能并没有你想象中那么好的。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">很多时候数据量大了,特别是有几亿条数据的时候,可能你会懵逼的发现,跑个搜索怎么一下 5~10s,坑爹了。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">第一次搜索的时候,是 5~10s,后面反而就快了,可能就几百毫秒。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">你就很懵,每个用户第一次访问都会比较慢,比较卡么?所以你要是没玩儿过 ES,或者就是自己玩玩儿 Demo,被问到这个问题容易懵逼,显示出你对 ES 确实玩的不怎么样?</span></p> <section class="" data-tools="135编辑器" data-id="39" data-color="#138bde"> <section class="" data-tools="135编辑器" data-id="39" data-color="#138bde" data-custom="#1e9be8"> <section> <p style="line-height: normal;"><br></p> </section> </section> </section> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">说实话,ES 性能优化是没有银弹的。</span><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">啥意思呢?就是不要期待着随手调一个参数,就可以万能的应对所有的性能慢的场景。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">也许有的场景是你换个参数,或者调整一下语法,就可以搞定,但是绝对不是所有场景都可以这样。</span></p> <p style="line-height: normal;"><br></p> <section class="" data-tools="135编辑器" data-id="86122" data-color="#138bde"> <section> <section> <section> <section style="box-sizing: border-box;font-size: 16px;"> <section style="box-sizing: border-box;" powered-by="xiumi.us"> <section style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: black;margin-top: 0.5em;margin-bottom: 0.5em;line-height: 1.2;box-sizing: border-box;"> <section style="display: inline-block;border-bottom-width: 6px;border-bottom-style: solid;border-color: rgb(89, 89, 89);margin-bottom: -1px;font-size: 20px;color: rgb(89, 89, 89);box-sizing: border-box;"> <p style="box-sizing: border-box;">性能优化的杀手锏:Filesystem Cache</p> </section> </section> </section> </section> <p style="line-height: normal;"><br></p> </section> </section> </section> </section> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;margin-bottom: 5px;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">你往 ES 里写的数据,实际上都写到磁盘文件里去了,查询的时候,操作系统会将磁盘文件里的数据自动缓存到 Filesystem Cache 里面去。</span></p> <p style="text-align: center;margin-left: 8px;margin-right: 8px;line-height: 1.75em;margin-bottom: 5px;"><img class="rich_pages " data-croporisrc="/upload/37bc9c8439d751a982ba02711a24aa93.jpg" data-cropx1="0" data-cropx2="515" data-cropy1="44" data-cropy2="484" data-ratio="0.8543689320388349" data-s="300,640" data-type="jpeg" data-w="515" src="https://mmbiz.qpic.cn/mmbiz_jpg/tibrg3AoIJTtmGR5Eb1iaOWMib3auLw3FWr3vOYdA7POCribHibIDQia3SbdPcaJDrAYQdMz7gqHuMeRicRrr5AiablonA/640?wx_fmt=jpeg" style="box-sizing: border-box !important;word-wrap: break-word !important;width: 515px !important;visibility: visible !important;"></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">ES 的搜索引擎严重依赖于底层的 Filesystem Cache,你如果给 Filesystem Cache 更多的内存,尽量让内存可以容纳所有的 IDX Segment File 索引数据文件,那么你搜索的时候就基本都是走内存的,性能会非常高。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;letter-spacing: 1px;color: rgb(71, 193, 168);">性能差距究竟可以有多大?</span><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">我们之前很多的测试和压测,如果走磁盘一般肯定上秒,搜索性能绝对是秒级别的,1 秒、5 秒、10 秒。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">但如果是走 Filesystem Cache,是走纯内存的,那么一般来说性能比走磁盘要高一个数量级,基本上就是毫秒级的,从几毫秒到几百毫秒不等。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><strong><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">这里有个真实的案例:</span></strong><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">某个公司 ES 节点有 3 台机器,每台机器看起来内存很多 64G,总内存就是 64 * 3 = 192G。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">每台机器给 ES JVM Heap 是 32G,那么剩下来留给 Filesystem Cache 的就是每台机器才 32G,总共集群里给 Filesystem Cache 的就是 32 * 3 = 96G 内存。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">而此时,整个磁盘上索引数据文件,在 3 台机器上一共占用了 1T 的磁盘容量,ES 数据量是 1T,那么每台机器的数据量是 300G。这样性能好吗?&nbsp;</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">Filesystem Cache 的内存才 100G,十分之一的数据可以放内存,其他的都在磁盘,然后你执行搜索操作,大部分操作都是走磁盘,性能肯定差。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">归根结底,你要让 ES 性能好,最佳的情况下,就是你的机器的内存,至少可以容纳你的总数据量的一半。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">根据我们自己的生产环境实践经验,最佳的情况下,是仅仅在 ES 中就存少量的数据,就是你要用来搜索的那些索引,如果内存留给 Filesystem Cache 的是 100G,那么你就将索引数据控制在 100G 以内。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">这样的话,你的数据几乎全部走内存来搜索,性能非常之高,一般可以在1秒以内。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">比如说你现在有一行数据:id,name,age .... 30 个字段。但是你现在搜索,只需要根据 id,name,age 三个字段来搜索。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">如果你傻乎乎往 ES 里写入一行数据所有的字段,就会导致说 90% 的数据是不用来搜索的。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">结果硬是占据了 ES 机器上的 Filesystem Cache 的空间,单条数据的数据量越大,就会导致 Filesystem Cahce 能缓存的数据就越少。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">其实,仅仅写入 ES 中要用来检索的少数几个字段就可以了,比如说就写入 es id,name,age 三个字段。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">然后你可以把其他的字段数据存在 MySQL/HBase 里,我们一般是建议用 ES + HBase 这么一个架构。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">HBase 的特点是适用于海量数据的在线存储,就是对 HBase 可以写入海量数据,但是不要做复杂的搜索,做很简单的一些根据 id 或者范围进行查询的这么一个操作就可以了。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">从 ES 中根据 name 和 age 去搜索,拿到的结果可能就 20 个 doc id,然后根据 doc id 到 HBase 里去查询每个 doc id 对应的完整的数据,给查出来,再返回给前端。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">写入 ES 的数据最好小于等于,或者是略微大于 ES 的 Filesystem Cache 的内存容量。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">然后你从 ES 检索可能就花费 20ms,然后再根据 ES 返回的 id 去 HBase 里查询,查 20 条数据,可能也就耗费个 30ms。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">可能你原来那么玩儿,1T 数据都放 ES,会每次查询都是 5~10s,现在可能性能就会很高,每次查询就是 50ms。</span></p> <p style="line-height: normal;"><br></p> <section class="" data-tools="135编辑器" data-id="86122" data-color="#138bde"> <section> <section> <section> <section style="box-sizing: border-box;font-size: 16px;"> <section style="box-sizing: border-box;" powered-by="xiumi.us"> <section style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: black;margin-top: 0.5em;margin-bottom: 0.5em;line-height: 1.2;box-sizing: border-box;"> <section style="display: inline-block;border-bottom-width: 6px;border-bottom-style: solid;border-color: rgb(89, 89, 89);margin-bottom: -1px;font-size: 20px;color: rgb(89, 89, 89);box-sizing: border-box;"> <p style="box-sizing: border-box;">数据预热</p> </section> </section> </section> </section> <p style="line-height: normal;"><br></p> </section> </section> </section> </section> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">假如说,哪怕是你就按照上述的方案去做了,ES 集群中每个机器写入的数据量还是超过了 Filesystem Cache 一倍。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">比如说你写入一台机器 60G 数据,结果 Filesystem Cache 就 30G,还是有 30G 数据留在了磁盘上。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">其实可以做数据预热。</span><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">举个例子,拿微博来说,你可以把一些大 V,平时看的人很多的数据,提前在后台搞个系统。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">每隔一会儿,自己的后台系统去搜索一下热数据,刷到 Filesystem Cache 里去,后面用户实际上来看这个热数据的时候,他们就是直接从内存里搜索了,很快。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">或者是电商,你可以将平时查看最多的一些商品,比如说 iPhone 8,热数据提前后台搞个程序,每隔 1 分钟自己主动访问一次,刷到 Filesystem Cache 里去。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">对于那些你觉得比较热的、经常会有人访问的数据,最好做一个专门的缓存预热子系统。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">就是对热数据每隔一段时间,就提前访问一下,让数据进入 Filesystem Cache 里面去。这样下次别人访问的时候,性能一定会好很多。</span></p> <p style="line-height: normal;"><br></p> <section class="" data-tools="135编辑器" data-id="86122" data-color="#138bde"> <section> <section> <section> <section style="box-sizing: border-box;font-size: 16px;"> <section style="box-sizing: border-box;" powered-by="xiumi.us"> <section style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: black;margin-top: 0.5em;margin-bottom: 0.5em;line-height: 1.2;box-sizing: border-box;"> <section style="display: inline-block;border-bottom-width: 6px;border-bottom-style: solid;border-color: rgb(89, 89, 89);margin-bottom: -1px;font-size: 20px;color: rgb(89, 89, 89);box-sizing: border-box;"> <p style="box-sizing: border-box;">冷热分离</p> </section> </section> </section> </section> <p style="line-height: normal;"><br></p> </section> </section> </section> </section> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">ES 可以做类似于 MySQL 的水平拆分,就是说将大量的访问很少、频率很低的数据,单独写一个索引,然后将访问很频繁的热数据单独写一个索引。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">最好是将冷数据写入一个索引中,然后热数据写入另外一个索引中,这样可以确保热数据在被预热之后,尽量都让他们留在 Filesystem OS Cache 里,别让冷数据给冲刷掉。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">你看,假设你有 6 台机器,2 个索引,一个放冷数据,一个放热数据,每个索引 3 个 Shard。3 台机器放热数据 Index,另外 3 台机器放冷数据 Index。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">这样的话,你大量的时间是在访问热数据 Index,热数据可能就占总数据量的 10%,此时数据量很少,几乎全都保留在 Filesystem Cache 里面了,就可以确保热数据的访问性能是很高的。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">但是对于冷数据而言,是在别的 Index 里的,跟热数据 Index 不在相同的机器上,大家互相之间都没什么联系了。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">如果有人访问冷数据,可能大量数据是在磁盘上的,此时性能差点,就 10% 的人去访问冷数据,90% 的人在访问热数据,也无所谓了。</span></p> <p style="line-height: normal;"><br></p> <section class="" data-tools="135编辑器" data-id="86122" data-color="#138bde"> <section> <section> <section> <section style="box-sizing: border-box;font-size: 16px;"> <section style="box-sizing: border-box;" powered-by="xiumi.us"> <section style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: black;margin-top: 0.5em;margin-bottom: 0.5em;line-height: 1.2;box-sizing: border-box;"> <section style="display: inline-block;border-bottom-width: 6px;border-bottom-style: solid;border-color: rgb(89, 89, 89);margin-bottom: -1px;font-size: 20px;color: rgb(89, 89, 89);box-sizing: border-box;"> <p style="box-sizing: border-box;">Document 模型设计</p> </section> </section> </section> </section> <p style="line-height: normal;"><br></p> </section> </section> </section> </section> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">对于 MySQL,我们经常有一些复杂的关联查询。在 ES 里该怎么玩儿,ES 里面的复杂的关联查询尽量别用,一旦用了性能一般都不太好。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">最好是先在 Java 系统里就完成关联,将关联好的数据直接写入 ES 中。搜索的时候,就不需要利用 ES 的搜索语法来完成 Join 之类的关联搜索了。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">Document 模型设计是非常重要的,很多操作,不要在搜索的时候才想去执行各种复杂的乱七八糟的操作。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">ES 能支持的操作就那么多,不要考虑用 ES 做一些它不好操作的事情。如果真的有那种操作,尽量在 Document 模型设计的时候,写入的时候就完成。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">另外对于一些太复杂的操作,比如 join/nested/parent-child 搜索都要尽量避免,性能都很差的。</span></p> <p style="line-height: normal;"><br></p> <section class="" data-tools="135编辑器" data-id="86122" data-color="#138bde"> <section> <section> <section> <section style="box-sizing: border-box;font-size: 16px;"> <section style="box-sizing: border-box;" powered-by="xiumi.us"> <section style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: black;margin-top: 0.5em;margin-bottom: 0.5em;line-height: 1.2;box-sizing: border-box;"> <section style="display: inline-block;border-bottom-width: 6px;border-bottom-style: solid;border-color: rgb(89, 89, 89);margin-bottom: -1px;font-size: 20px;color: rgb(89, 89, 89);box-sizing: border-box;"> <p style="box-sizing: border-box;">分页性能优化</p> </section> </section> </section> </section> <p style="line-height: normal;"><br></p> </section> </section> </section> </section> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">ES 的分页是较坑的,为啥呢?</span><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">举个例子吧,假如你每页是 10 条数据,你现在要查询第 100 页,实际上是会把每个 Shard 上存储的前 1000 条数据都查到一个协调节点上。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">如果你有 5 个 Shard,那么就有 5000 条数据,接着协调节点对这 5000 条数据进行一些合并、处理,再获取到最终第 100 页的 10 条数据。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">分布式的,你要查第 100 页的 10 条数据,不可能说从 5 个 Shard,每个 Shard 就查 2 条数据,最后到协调节点合并成 10 条数据吧?</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">你必须得从每个 Shard 都查 1000 条数据过来,然后根据你的需求进行排序、筛选等等操作,最后再次分页,拿到里面第 100 页的数据。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">你翻页的时候,翻的越深,每个 Shard 返回的数据就越多,而且协调节点处理的时间越长,非常坑爹。所以用 ES 做分页的时候,你会发现越翻到后面,就越是慢。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">我们之前也是遇到过这个问题,用 ES 作分页,前几页就几十毫秒,翻到 10 页或者几十页的时候,基本上就要 5~10 秒才能查出来一页数据了。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">有什么解决方案吗?</span><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">不允许深度分页(默认深度分页性能很差)。跟产品经理说,你系统不允许翻那么深的页,默认翻的越深,性能就越差。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">类似于 App 里的推荐商品不断下拉出来一页一页的;</span><span style="color: rgb(89, 89, 89);font-size: 15px;letter-spacing: 1px;line-height: 1.75em;">类似于微博中,下拉刷微博,刷出来一页一页的,你可以用 Scroll API,关于如何使用,自行上网搜索。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">Scroll 会一次性给你生成所有数据的一个快照,然后每次滑动向后翻页就是通过游标 scroll_id 移动,获取下一页、下一页这样子,性能会比上面说的那种分页性能要高很多很多,基本上都是毫秒级的。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">但是,唯一的一点就是,这个适合于那种类似微博下拉翻页的,不能随意跳到任何一页的场景。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">也就是说,你不能先进入第 10 页,然后去第 120 页,然后又回到第 58 页,不能随意乱跳页。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">所以现在很多产品,都是不允许你随意翻页的,App,也有一些网站,做的就是你只能往下拉,一页一页的翻。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">初始化时必须指定 Scroll 参数,告诉 ES 要保存此次搜索的上下文多长时间。你需要确保用户不会持续不断翻页翻几个小时,否则可能因为超时而失败。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">除了用 Scroll API,你也可以用 search_after 来做。search_after 的思想是使用前一页的结果来帮助检索下一页的数据。</span></p> <p style="line-height: normal;"><br></p> <p style="text-align: justify;margin-left: 8px;margin-right: 8px;line-height: 1.75em;"><span style="font-size: 15px;color: rgb(89, 89, 89);letter-spacing: 1px;">显然,这种方式也不允许你随意翻页,你只能一页页往后翻。初始化时,需要使用一个唯一值的字段作为 Sort 字段。</span></p> <p style="line-height: normal;"><br></p> <p style="white-space: normal;line-height: 1.75em;"><span style="color: rgb(89, 89, 89);letter-spacing: 1px;"><em><span style="font-size: 14px;">作者:节操泛滥的程序员</span></em></span></p> <p style="white-space: normal;line-height: 1.75em;"><span style="color: rgb(89, 89, 89);letter-spacing: 1px;"><em><span style="font-size: 14px;">编辑:陶家龙、孙淑娟</span></em></span><br></p> <p style="line-height: 1.75em;"><span style="font-size: 14px;color: rgb(89, 89, 89);letter-spacing: 1px;"><em>出处:https://zhuanlan.zhihu.com/p/60458049</em></span></p> <p style="text-align: center;"><img class="rich_pages" data-copyright="0" data-ratio="0.3939393939393939" src="/upload/58a14061a632a0fe87d40beb73c1aa.gif" data-type="gif" data-w="660" style=""></p> <section style="box-sizing: border-box;font-size: 16px;"> <section style="box-sizing: border-box;" powered-by="xiumi.us"> <section style="margin-top: 0.5em;margin-bottom: 0.5em;box-sizing: border-box;"> <section style="font-size: 15px;border-style: solid;border-width: 0px 0px 1px;color: rgb(89, 89, 89);border-bottom-color: rgba(215, 215, 215, 0.960784);box-sizing: border-box;"> <p style="box-sizing: border-box;"><span style="letter-spacing: 1px;"><strong>精彩文章推荐:</strong></span></p> </section> </section> </section> </section> <p style="line-height: 2em;"><a href="http://mp.weixin.qq.com/s?__biz=MjM5ODI5Njc2MA==&amp;mid=2655824391&amp;idx=1&amp;sn=ac183b0cc7b1ee2ea0c10c1d4abf6fc0&amp;chksm=bd74e7d08a036ec6bc54c31519a1391758741977f646f711bc17e2be69b1f333ea2ee0078137&amp;scene=21#wechat_redirect" target="_blank" data-itemshowtype="0" style="font-size: 14px;color: rgb(89, 89, 89);letter-spacing: 1px;text-decoration: none;" data-linktype="2"><span style="font-size: 14px;color: rgb(89, 89, 89);letter-spacing: 1px;">搞定高并发,岂能不懂Synchronized底层原理?</span></a><br></p> <p style="line-height: 2em;"><a href="http://mp.weixin.qq.com/s?__biz=MjM5ODI5Njc2MA==&amp;mid=2655824323&amp;idx=1&amp;sn=2cd6852e7baae4b00c68d2678b5e23cc&amp;chksm=bd74e4148a036d02831449be2301f2c83faabdd03760ba970a63a1d5c2c19c603b4108ebcc77&amp;scene=21#wechat_redirect" target="_blank" data-itemshowtype="0" style="font-size: 14px;color: rgb(89, 89, 89);letter-spacing: 1px;text-decoration: none;" data-linktype="2"><span style="font-size: 14px;color: rgb(89, 89, 89);letter-spacing: 1px;">超详细的Elasticsearch高性能优化实践</span></a><br></p> <p style="line-height: 2em;"><a href="http://mp.weixin.qq.com/s?__biz=MjM5ODI5Njc2MA==&amp;mid=2655824393&amp;idx=1&amp;sn=5a31b81285dca2818cecc898d42760ab&amp;chksm=bd74e7de8a036ec81b2c08d19a71a04e43b575e5a1959d852d59410fb7bd3a31087dde560d5d&amp;scene=21#wechat_redirect" target="_blank" data-itemshowtype="0" style="font-size: 14px;color: rgb(89, 89, 89);letter-spacing: 1px;text-decoration: none;" data-linktype="2"><span style="font-size: 14px;color: rgb(89, 89, 89);letter-spacing: 1px;">在阿里,我如何做好一个项目的启动?</span></a><br></p>