翻译翻译:什么叫架构?
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">以下<span style="color: black;">文案</span><span style="color: black;">源自</span>方志朋的博客,回复”666“获面试宝典</span></span></p><span style="color: black;">作者:Yrion | 链接:cnblogs.com/wyq178/p/12151160.html</span><span style="color: black;">这个知识分享的爆炸时代,鉴于 Java 生态的完整和繁荣,<span style="color: black;">各样</span>框架、中间件和<span style="color: black;">工具</span>包供<span style="color: black;">咱们</span><span style="color: black;">运用</span>。连新培训出来的人都<span style="color: black;">晓得</span> SSM,微服务、集群、多线程、队列、高并发等技术,技术的间隔性正变得越来越小,仿佛<span style="color: black;">咱们</span>只<span style="color: black;">必须</span>按部就班的去<span style="color: black;">运用</span>别人说的框架等技术就<span style="color: black;">能够</span><span style="color: black;">处理</span>问题。</span><span style="color: black;"><span style="color: black;">倘若</span>刨除redis、rabbitmq、kafka、dubbo、springcloud这些<span style="color: black;">详细</span>的技术框架,你有<span style="color: black;">无</span>静下心来真正思考过架构是什么呢?这些框架是<span style="color: black;">到底</span>是扮演怎么样的角色?<span style="color: black;">倘若</span>不说<span style="color: black;">各样</span>天花乱坠的概念,让你给架构下一个定义,你会<span style="color: black;">选取</span><span style="color: black;">怎样</span>去描述架构呢?</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">翻译翻译,什么是架构?</span></p><img src="https://mmbiz.qpic.cn/mmbiz_png/oTKHc6F8tsgr658Aickd6hjMUCGY0tjgNTzmclCnJ0G3AeV82CP9vFvxOerbCJtOtoYGJcBUL7C1WrxFynyIDow/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">背景</strong>: 从业快 4 年.我记得在我刚从业的时候,当时流行的框架是 spring、struts2、hibernate,前端<span style="color: black;">运用</span>的是 jsp,业务<span style="color: black;">亦</span>不是<span style="color: black;">那样</span><span style="color: black;">繁杂</span>,<span style="color: black;">全部</span>项目并发量并不大,QPS 都不会超过5,当时的做法所有的前端和后端放在<span style="color: black;">一块</span><span style="color: black;">安排</span>,打成war包直接<span style="color: black;">安排</span>到centos上的tomcat上就<span style="color: black;">能够</span>运行了,<span style="color: black;">这般</span>完全<span style="color: black;">能够</span>承载<span style="color: black;">实质</span>生产环境的请求量,问题<span style="color: black;">亦</span>不大。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">后来当我换了一家<span style="color: black;">机构</span>,<span style="color: black;">机构</span>采用 dubbo 微服务化,所有的业务均被划分<span style="color: black;">成为了</span>一个个服务来<span style="color: black;">供给</span>给接口调用,当时的业务场景<span style="color: black;">亦</span>比以前的<span style="color: black;">繁杂</span>,采用23台服务器<span style="color: black;">掰开</span><span style="color: black;">安排</span>,容纳的线上负载大概在几百万<span style="color: black;">上下</span>。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">服务进行修改<span style="color: black;">规律</span>再<span style="color: black;">亦</span><span style="color: black;">不消</span>像以前<span style="color: black;">那样</span>麻烦<span style="color: black;">必须</span>把<span style="color: black;">全部</span>项目重新打包再<span style="color: black;">安排</span>了.之后就在微服务的路上走的更远了,所有的服务独立<span style="color: black;">安排</span>,打包成镜像文件<span style="color: black;">作为</span> docke r实例,独立<span style="color: black;">安排</span>在 docker 的服务器上,结合git,<span style="color: black;">安排</span>、运维、<span style="color: black;">研发</span>的效率得到了<span style="color: black;">快速</span><span style="color: black;">提高</span>。</span></p><span style="color: black;"><strong style="color: blue;">目录</strong> </span><span style="color: black;">一:架构到底是什么</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">二:常用的架构技术</span></p> <span style="color: black;">2.1:分布式</span> <span style="color: black;">2.2:集群</span> <span style="color: black;">2.3:缓存</span> <span style="color: black;">2.4:队列</span> <span style="color: black;">2.5:多线程</span> <span style="color: black;">2.6:限流</span> <span style="color: black;">2.7:服务降级和熔断</span><span style="color: black;">三:安全性问题</span> <span style="color: black;">3.1 sql注入</span> <span style="color: black;">3.2 跨域攻击</span> <span style="color: black;">3.3:XSS攻击</span><span style="color: black;">四: 架构设计的误区</span> <span style="color: black;">4.1:为了<span style="color: black;">高挑</span>上而设计出<span style="color: black;">繁杂</span>的架构</span> <span style="color: black;">4.2:用技术<span style="color: black;">能够</span><span style="color: black;">处理</span>一切问题</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">一:架构到底是什么</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">架构到底是什么?<span style="color: black;">首要</span>来看一下维基百科对架构的解释:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">软件架构:</strong>是一个系统的草图。软件架构描述的对象是直接<span style="color: black;">形成</span>系统的抽象组件。各个组件之间的连接则<span style="color: black;">知道</span>和相对细致地描述组件之间的通讯。在实现<span style="color: black;">周期</span>,这些抽象组件被细化为<span style="color: black;">实质</span>的组件,<span style="color: black;">例如</span><span style="color: black;">详细</span>某个类<span style="color: black;">或</span>对像。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">软件架构师:</span></strong><span style="color: black;">软件架构师定义和设计软件的模块化,模块之间的交互,用户界面风格,对外接口<span style="color: black;">办法</span>,创新的设计特性,以及高层事物的对象操作、<span style="color: black;">规律</span>和流程。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> <span style="color: black;">根据</span>维基百科的解释:软件架构实则是各个组件的互相搭配和组件之间的相互<span style="color: black;">协同</span>,是抽象的高层事务的的<span style="color: black;">规律</span>流程。简单<span style="color: black;">来讲</span>架构<span style="color: black;">便是</span>各个系统组件<span style="color: black;">怎样</span>通讯、协调、以及<span style="color: black;">掌控</span>操作的<span style="color: black;">规律</span>。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">能够</span>类比人体的结构来举个简单的例子来理解<span style="color: black;">便是</span>:人体<span style="color: black;">是由于</span>心肝脾肺胃、耳鼻嘴等多个<span style="color: black;">要紧</span>器官<span style="color: black;">构成</span>,各个器官各司其职,它们之间相互<span style="color: black;">协同</span><span style="color: black;">一起</span>维持人的正常生活。<span style="color: black;">这儿</span>的心、胃等<span style="color: black;">便是</span><span style="color: black;">全部</span>人体架构的组件,血液<span style="color: black;">便是</span>数据,血管<span style="color: black;">便是</span>传输数据的媒介,人的皮肤和长相<span style="color: black;">便是</span>用户的界面风格,<span style="color: black;">规律</span>组织<span style="color: black;">便是</span><span style="color: black;">食品</span>要<span style="color: black;">首要</span>进入胃去消化<span style="color: black;">而后</span>才会进入大肠,而不是进入肾脏。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">根据</span>这个解释,<span style="color: black;">咱们</span><span style="color: black;">运用</span>的kafka、redis、ssm、rabbitmq、xxljob等都是组件,这些组件各有各的<span style="color: black;">功效</span>,各自承担自己的责任去<span style="color: black;">一起</span>完成<span style="color: black;">全部</span>系统的<span style="color: black;">有效</span>流转.</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">二:常用的架构技术</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">2.1:分布式</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">分布式:将同一套业务代码<span style="color: black;">根据</span>业务功能<span style="color: black;">或</span>自定义的维度拆分<span style="color: black;">区别</span>的子系统,各个系统<span style="color: black;">掰开</span><span style="color: black;">安排</span>,<span style="color: black;">每一个</span>子系统叫做服务,<span style="color: black;">每一个</span>服务之间<span style="color: black;">通常</span><span style="color: black;">经过</span>rpc<span style="color: black;">或</span>webservice来调用</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2.1.1: 分布式的优点</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">分布式的好处<span style="color: black;">便是</span>解耦了原系统,从而便于运维<span style="color: black;">安排</span>和水平扩展,<span style="color: black;">供给</span>软件的伸缩性,<span style="color: black;">乃至</span>服务<span style="color: black;">能够</span><span style="color: black;">经过</span><span style="color: black;">区别</span>的语言来实现.各个模块交给<span style="color: black;">区别</span>的人员去<span style="color: black;">研发</span>,<span style="color: black;">每一个</span>人各司其职,<span style="color: black;">显现</span>问题<span style="color: black;">亦</span><span style="color: black;">能够</span>快速定位</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2.1.1:分布式的缺点</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">分布式<span style="color: black;">亦</span>并不是毫<span style="color: black;">没</span>缺点的,存在以下的问题:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">①</strong>:服务调用<span style="color: black;">经过</span>网络来调用,<span style="color: black;">通常</span>微服务之间<span style="color: black;">运用</span>rpc来调用的,而rpc的底层<span style="color: black;">便是</span>TCP协议,<span style="color: black;">倘若</span>网络故障<span style="color: black;">或</span>延迟高一点,<span style="color: black;">那样</span>服务调用就有<span style="color: black;">显现</span>超时的可能性,<span style="color: black;">例如</span>dubbo的话会<span style="color: black;">显现</span>RpcException</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">②</strong>:分布式在业务体量比较小<span style="color: black;">或</span>粒度划分的<span style="color: black;">状况</span>下<span style="color: black;">便是</span>一种<span style="color: black;">劫难</span>式<span style="color: black;">研发</span>,<span style="color: black;">研发</span>和运维的成本都会直线上升</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">③</strong>:分布式的数据一致性和事务比较难以<span style="color: black;">保证</span>,业务<span style="color: black;">日前</span><span style="color: black;">运用</span>最多的是两<span style="color: black;">周期</span>提交2pc,<span style="color: black;">必须</span>本地事务和远程事务综合提交,性能比较差</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">④</strong>:分布式session的<span style="color: black;">守护</span>在单体工程中是不<span style="color: black;">必须</span><span style="color: black;">思虑</span>session的安全性的,而在分布式环境中就<span style="color: black;">必要</span><span style="color: black;">思虑</span><span style="color: black;">怎样</span>去<span style="color: black;">守护</span>session的一致</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">⑤:</strong>分布式事务问题<strong style="color: blue;">:</strong>分布式下<span style="color: black;">怎样</span><span style="color: black;">保准</span>各个服务的数据一致性<span style="color: black;">亦</span>是一种挑战,当程序<span style="color: black;">显现</span><span style="color: black;">反常</span>崩溃的时候能够<span style="color: black;">保准</span>各个服务能够正常回滚是很<span style="color: black;">要紧</span>的。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">分布式最<span style="color: black;">平常</span>的技术:分布式缓存、分布式存储、分布式计算、分布式静态资源</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">2.2:集群</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">集群:同一套代码<span style="color: black;">安排</span>在多个服务器上,而多个服务器<span style="color: black;">能够</span><span style="color: black;">供给</span><span style="color: black;">更加多</span>的cpu、内存、硬盘等资源,从而<span style="color: black;">提高</span>整理的处理请求能力。集群的每个服务器叫做节点,<span style="color: black;">每一个</span>节点<span style="color: black;">供给</span>的是相同的服务,节点的关系只是一种简单的复制,<span style="color: black;">详细</span>是哪个节点处理,则是<span style="color: black;">按照</span>负载<span style="color: black;">平衡</span>策略来决定;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在网站的处理能力<span style="color: black;">显现</span>下滑的时候,简单的在集群中<span style="color: black;">增多</span>服务器台数就<span style="color: black;">能够</span><span style="color: black;">明显</span><span style="color: black;">增多</span>整体的数据量处理能力(<span style="color: black;">不外</span>存在上限);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> 原理很简单:<span style="color: black;">所说</span><strong style="color: blue;">众人拾柴火焰高,</strong>多台服务器<span style="color: black;">一块</span>聚合处理数据量和并发<span style="color: black;">拜访</span>的能力肯定比单台服务器要高<span style="color: black;">非常多</span>;在遇到请求处理的瓶颈时候,<span style="color: black;">能够</span><span style="color: black;">经过</span>简单的<span style="color: black;">增多</span>服务器台数来<span style="color: black;">加强</span>并行处理的能力,<span style="color: black;">不外</span><span style="color: black;">必须</span><span style="color: black;">重视</span>的是<span style="color: black;">增多</span>服务器台数在<span style="color: black;">显现</span>大于某个数量之后性能会停滞不前。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/oTKHc6F8tsgr658Aickd6hjMUCGY0tjgNWbETnR9ZuVAZKb1ibyUult0EvqnEoaDPtwqlibyRdzdZBKzyvfdNWpRA/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">2.3:缓存</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">缓存是<span style="color: black;">加强</span>软件的性能<span style="color: black;">第1</span>手段,最有效和最具<span style="color: black;">表率</span>性的<span style="color: black;">办法</span>,缓存分为单机缓存和分布式缓存。最<span style="color: black;">平常</span>的分布式缓存技术为redis、memorycache等,单机缓存<span style="color: black;">例如</span>hashmap、concurrentHashmap、guava等</span><strong style="color: blue;">。</strong><span style="color: black;">单机缓存的承载容量有限,而分布式缓存的伸缩性和的存储容量会比较可观,就算缓存的空间不足了,<span style="color: black;">亦</span><span style="color: black;">能够</span><span style="color: black;">经过</span><span style="color: black;">增多</span>服务器来扩展。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">缓存最<span style="color: black;">明显</span>的<span style="color: black;">功效</span>有两个:①加快数据的<span style="color: black;">拜访</span>速度 ②分担后端的数据<span style="color: black;">拜访</span>和存储的负载能力,<span style="color: black;">守护</span>数据库</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/oTKHc6F8tsgr658Aickd6hjMUCGY0tjgNdNocibluia3R92uwOHf5ia27QtyLVxOsNWK5uvXUdUPxyCf6ZaMHjs9lQ/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">运用</span>缓存<span style="color: black;">必须</span><span style="color: black;">重视</span>以下几点:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">①: 缓存雪崩</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">缓存雪崩指的是所有的缓存在统一时间<span style="color: black;">所有</span>失效,<span style="color: black;">引起</span><span style="color: black;">海量</span>的请求直接涌入数据库,数据库被击垮。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">处理</span>缓存雪崩的<span style="color: black;">办法</span>:缓存过期值在<span style="color: black;">必定</span>的<span style="color: black;">基本</span>上设置随机值</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">②: 缓存击穿</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">缓存击穿<span style="color: black;">指的是</span>某些热点key在某一时间<span style="color: black;">所有</span>失效了,<span style="color: black;">引起</span><span style="color: black;">海量</span>的请求涌入后台DB数据库,<span style="color: black;">处理</span>缓存击穿的<span style="color: black;">办法</span>:热点数据设置永<span style="color: black;">不外</span>期</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">③:缓存穿透</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> <span style="color: black;">始终</span>请求不存在的数据,<span style="color: black;">最后</span>走的还是数据库<span style="color: black;">便是</span>缓存穿透</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">处理</span>缓存穿透的<span style="color: black;">办法</span>:采用布隆过滤器(bloomFilter),布隆过滤会有<span style="color: black;">必定</span>的误差,<span style="color: black;">然则</span><span style="color: black;">能够</span>晒选出<span style="color: black;">必定</span>不存在的数据,缺点是<span style="color: black;">没</span>法判定某个key<span style="color: black;">是不是</span>确定存在。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> <strong style="color: blue;">2.4:</strong><strong style="color: blue;">队列</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">试想<span style="color: black;">这般</span>一个的高请求量场景:各大电商的双11,在双11的那一刻,有<span style="color: black;">海量</span>订单涌入,后端会接受请求,<span style="color: black;">而后</span>写入数据库,等待数据库的返回.<span style="color: black;">倘若</span>请求量非常大的话,数据库读写IO就会阻塞,<span style="color: black;">那样</span>程序就会<span style="color: black;">显现</span>卡死,数据库崩溃等问题。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span>采用队列的话,将下单请求发送到队列中,<span style="color: black;">而后</span>立刻返回(<span style="color: black;">能够</span><span style="color: black;">根据</span>业务决定,<span style="color: black;">例如</span>返回处理中,等到真正成功再<span style="color: black;">通告</span>用户),<span style="color: black;">这般</span>就不<span style="color: black;">必须</span>等待后端<span style="color: black;">必要</span>返回成功。消费端<span style="color: black;">能够</span><span style="color: black;">根据</span>请求的<span style="color: black;">次序</span>平滑的去消费,缓解了高峰的请求,并且实现了请求下单和实现下单的解耦<strong style="color: blue;">。</strong>从以下图<span style="color: black;">能够</span>看出<span style="color: black;">运用</span>队列以后处理起来比较平滑~</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/oTKHc6F8tsgr658Aickd6hjMUCGY0tjgNQ7BP7XxCiaqCQ6qekiaMXcrT66jT1kw0LicyaNESuh4BjF3Dxn2wENwvA/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> <strong style="color: blue;">2.5:多线程</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">多线程真正的<span style="color: black;">道理</span>有两个①<span style="color: black;">加强</span>cpu的利用率 ②:加快程序执行效率,<span style="color: black;">日前</span><span style="color: black;">已然</span>是多核的时代,服务器六核、八核屡见不鲜,在多核的cpu中<span style="color: black;">倘若</span><span style="color: black;">运用</span>单线程<span style="color: black;">那样</span><span style="color: black;">没</span>疑是对多核cpu的浪费,多线程能够有效<span style="color: black;">加强</span>cpu利用的效率,多个任务分给多个cpu去处理,<span style="color: black;">能够</span>实现真正的并行处理。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span>在单核cpu中,只是cpu在<span style="color: black;">一直</span>的切换cpu时间。假设<span style="color: black;">咱们</span>有十个表格的数据<span style="color: black;">必须</span>分析处理(计算密集型),采用单线程<span style="color: black;">必须</span>一个个的轮询表格,而多线程在<span style="color: black;">恰当</span>分配线程数的<span style="color: black;">状况</span>下就<span style="color: black;">能够</span><span style="color: black;">同期</span>处理,<span style="color: black;">加强</span><span style="color: black;">研发</span>的效率</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> <strong style="color: blue;"> 2.6:限流</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">限流是面对高并发的利器之一,例如秒杀场景:在<span style="color: black;">海量</span>的请求涌入后台,QPS高达几十万,<span style="color: black;">倘若</span><span style="color: black;">不可</span>做到有效<span style="color: black;">掌控</span>就可能<span style="color: black;">引起</span>请求击垮数据库,DB基本上是一个网站的命脉。缓存、队列、限流等方式的本质其实都是为了<span style="color: black;">守护</span>DB。限流的简单理解其实<span style="color: black;">便是</span>过滤掉<span style="color: black;">没</span>效的请求,将请求限制在一个<span style="color: black;">能够</span><span style="color: black;">掌控</span>的范围内,最<span style="color: black;">平常</span>的限流有以下方式:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> <strong style="color: blue;">①: </strong><strong style="color: blue;">Redis</strong><strong style="color: blue;">限流</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Redis限流的基本思路是采用redis的key过期策略,将业务id和业务值放入到redis中设置<span style="color: black;">必定</span>的过期时间,等请求再次进入的时候,<span style="color: black;">倘若</span>能从redis获取到值,<span style="color: black;">那样</span>我就<span style="color: black;">由于</span>是重复性请求。Redis过滤限流是最<span style="color: black;">基本</span>的限流手段,适用于过滤同一个用户请求的场景</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">②:</strong><strong style="color: blue;">令牌桶算法</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">令牌桶算法的思路是在<span style="color: black;">必定</span>的时间内生成以固定的速度生成有限个令牌数量放入桶中,所有的请求<span style="color: black;">首要</span>从令牌桶中去尝试获取令牌,<span style="color: black;">倘若</span>能获取到就<span style="color: black;">能够</span>继续执行,否则请求就会被抛弃。Google开源的guava中有RateLimter<span style="color: black;">能够</span>实现单机限流,<strong style="color: blue;">令牌桶算法是限流非常有效的手段,</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">③: </strong><strong style="color: blue;">漏桶算法</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">漏桶算法的基本原理是将请求直接存放在一个漏斗中,请求<span style="color: black;">太多</span>的话,<span style="color: black;">那样</span>就会漏斗就会溢出,溢出的请求则会被拒绝服务。漏桶算法<span style="color: black;">能够</span><span style="color: black;">掌控</span>端口的流量输出速率,平滑请求的突发流量,实现流量整形.</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">由于</span>漏桶算法的漏出速率是有效的,<span style="color: black;">因此呢</span>漏桶算法相比于令牌桶算法有一个<span style="color: black;">明显</span>的缺点是<span style="color: black;">没</span>法应对突发性的流量.可令牌桶算法是<span style="color: black;">能够</span>的</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">④: 滑动窗口</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">http为了<span style="color: black;">掌控</span>流量的速率采用的<span style="color: black;">办法</span><span style="color: black;">便是</span>滑动窗口机制。<span style="color: black;">倘若</span>要分布式限流,可采用阿里的Sentinel框架,其基本原理是滑动窗口机制,利用Entry映射资源来平滑的限流</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">另外</span>还有nginx限流,<span style="color: black;">例如</span><span style="color: black;">运用</span>参数来限制某一个ip的在时间范围内的<span style="color: black;">拜访</span>频率。客户端限流:发起请求按钮点击后,在后面的几秒内(由业务决定)设置为disabled,这一操作<span style="color: black;">过程</span>虽然很小,<span style="color: black;">然则</span>带来的限流<span style="color: black;">功效</span>很可观</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">2.7:服务降级和熔断</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">非常多</span>人会<span style="color: black;">忽略</span>这个问题,对自己设计出来的架构<span style="color: black;">茫然</span>自信,认为不可能出问题。而事实上,一旦随着微服务和分布式架构的<span style="color: black;">连续</span>推进,服务器会越来越多,宕机的概率和可能性会逐步<span style="color: black;">提高</span>,虽然<span style="color: black;">显现</span>宕机的可能性基本上很渺茫,<span style="color: black;">不外</span><span style="color: black;">亦</span>应该做好服务降级和熔断的准备,以防止那万分之一的概率宕机。假设有1000台服务器<span style="color: black;">出现</span>宕机的概率是0.001%,就<span style="color: black;">由于</span>存在0.001%的概率会<span style="color: black;">引起</span><span style="color: black;">咱们</span>的服务并非100%高可用。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">服务的降级和熔断<span style="color: black;">通常</span>采用的是netfly(没错,<span style="color: black;">便是</span>那个美剧巨头<span style="color: black;">机构</span>)出的hystrix,<span style="color: black;">能够</span>实现服务熔断和降级</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">三:安全性问题</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">安全性的问题总是不被<span style="color: black;">注重</span>,其实安全的问题要比<span style="color: black;">咱们</span>想像的要严重的多.大<span style="color: black;">机构</span>每时每刻都会有<span style="color: black;">区别</span>程度被攻击者发起攻击,一旦被黑客获取到数据库信息,<span style="color: black;">那样</span>将会有丢失用户信息、服务器被<span style="color: black;">移植</span>木马病毒、服务瘫痪等不容小觑的危险</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">3.1 sql</strong><strong style="color: blue;">注入</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">sql注入是<span style="color: black;">日前</span>所有方式中最频繁<span style="color: black;">亦</span>是最严重的攻击手段,sql注入<span style="color: black;">倘若</span>被居心叵测的黑客攻击很可能<span style="color: black;">全部</span>数据库都会被删除掉,其情节和结果<span style="color: black;">非常</span><span style="color: black;">卑劣</span>。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">防止sql注入的有效方式<span style="color: black;">便是</span>采用jdbc<span style="color: black;">供给</span>的preparementStatement进行预编译,它能有效<span style="color: black;">保准</span>sql的整体结构不会被破坏,万一被sql攻击<span style="color: black;">亦</span><span style="color: black;">能够</span>在预编译<span style="color: black;">周期</span>失败,而不会执行成功。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">3.2 跨域攻击 </strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">与主站的域名、端口、协议不一致性的请求都<span style="color: black;">能够</span>理解为跨域<span style="color: black;">拜访</span>,浏览器有同源策略:浏览器会限制来自于<span style="color: black;">区别</span>源的documet和脚本对当前的document读取或设置部分属性,<span style="color: black;">然则</span><span style="color: black;">例如</span>src\form表单提交\< img >\< iframe >\< link >是<span style="color: black;">无</span>跨域限制的。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">csrf攻击:登陆网站A,获取到了网站A的cookie用户信息,<span style="color: black;">而后</span>点击了一个恶意网站外链B,网站B<span style="color: black;">能够</span>利用csrf漏洞模拟A网站的用户信息去请求A的某些<span style="color: black;">敏锐</span>接口,<span style="color: black;">例如</span>转账、发送<span style="color: black;">信息</span>、邮件、获取部分信息、发起恶意代码等。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">怎样</span>防止csrf攻击:①接口请求加上随机的token值<span style="color: black;">或</span>token约束的规则,<span style="color: black;">或</span>是有时效性的token码。<span style="color: black;">这般</span>的话,外链去<span style="color: black;">拜访</span>接口在拦截器中验证token<span style="color: black;">是不是</span>有效,②在http的头部加入自定义参数:放到 HTTP 头中自定义的属性里。<span style="color: black;">经过</span> Ajax,<span style="color: black;">能够</span>一次性给所有该类请求加上 csrftoken 这个 HTTP 头属性,并把 token 值放入其中</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">③减少<span style="color: black;">运用</span>get提交,get提交会降低门槛</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">3.3:XSS攻击</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">xss攻击指的是攻击者对<span style="color: black;">包括</span>有漏洞的服务器注入js代码,会诱使受害者打开攻击的服务器URL,其中里面的URL会<span style="color: black;">包括</span><span style="color: black;">有些</span>恶意代码,<span style="color: black;">例如</span><span style="color: black;">移植</span>病毒、添加<span style="color: black;">宣传</span>片段代码、篡改接口信息等。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">预防xss攻击的<span style="color: black;">办法</span>:<span style="color: black;">针对</span>用户提交的内容,<span style="color: black;">必须</span></span><span style="color: black;">过滤任何有执行能力的脚本<span style="color: black;">或</span>影响页面的CSS,</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> <strong style="color: blue;">四: 架构设计的误区</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">4.1:为了<span style="color: black;">高挑</span>上而设计出<span style="color: black;">繁杂</span>的架构</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">试想<span style="color: black;">倘若</span>在业务体量不是特点大的<span style="color: black;">状况</span>下,<span style="color: black;">倘若</span>一味的追求时髦,追求新颖,采用分布式微服务架构,<span style="color: black;">那样</span>将会<span style="color: black;">增多</span>业务<span style="color: black;">研发</span>的难度,为了<span style="color: black;">守护</span><span style="color: black;">海量</span>的微服务而多出<span style="color: black;">非常多</span>成本。好的架构<span style="color: black;">必定</span>是适应于<span style="color: black;">自己</span>的业务发展的,而高于业务的,它<span style="color: black;">拥有</span>顺应业务发展的前瞻性。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">4.3:用技术<span style="color: black;">能够</span><span style="color: black;">处理</span>一切问题</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">企图用技术<span style="color: black;">处理</span>一切问题,认为技术是一切的<span style="color: black;">处理</span>之道,是万能的,其实有的时候技术<span style="color: black;">处理</span>不了的问题<span style="color: black;">能够</span>用从业务<span style="color: black;">方向</span>来<span style="color: black;">思虑</span><span style="color: black;">处理</span>。<span style="color: black;">例如</span>之前楼主做个售票系统,<span style="color: black;">重点</span>是卖某个知名景点的票的业务。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">后期上线后<span style="color: black;">发掘</span><span style="color: black;">非常多</span>人买了<span style="color: black;">非常多</span>特价免费票,特价票是针对导游带领的团员的,<span style="color: black;">每一个</span>导游<span style="color: black;">每日</span>只能买一张特价免费票和一张半价票,之后看数据<span style="color: black;">发掘</span>了<span style="color: black;">非常多</span>导游配了两张票,<span style="color: black;">而后</span>那张半价票被退掉,只剩下一张免费票被刷了。技术总监就决定查这部分数据是怎么回事?</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">结果<span style="color: black;">发掘</span>部分人利用导游证这个特惠故意购买<span style="color: black;">没</span>价票,这个问题<span style="color: black;">怎样</span>从技术上<span style="color: black;">处理</span>呢?<span style="color: black;">倘若</span>不<span style="color: black;">准许</span>导游买特惠票不<span style="color: black;">恰当</span>,不<span style="color: black;">准许</span>退票<span style="color: black;">亦</span>不<span style="color: black;">恰当</span>。技术上貌似<span style="color: black;">无</span>好的手段去杜绝这个问题,只能从线下去处理。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">五:总结</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">本篇<span style="color: black;">文案</span>的<span style="color: black;">重点</span>概略图我总结了一下,大概如下,其中<span style="color: black;">包含</span>分布式、集群、缓存、微服务、队列等,这<span style="color: black;">关联</span>的<span style="color: black;">文案</span>都发布过,关注公众号「Java后端」关注后回复「666」下载一本技术栈手册就<span style="color: black;">能够</span>看到历史发布的技术<span style="color: black;">文案</span>。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">架构的<span style="color: black;">专题</span>弥足长远和<span style="color: black;">繁杂</span>,不是一篇简单的<span style="color: black;">文案</span>能描述清楚的。本篇<span style="color: black;">文案</span>只是提纲挈领以下,说实话<span style="color: black;">亦</span>是蜻蜓点水,<span style="color: black;">期盼</span>能起到抛砖引玉的效果,<span style="color: black;">不外</span>在工作中思考、在实践中总结学习,是有助于<span style="color: black;">加强</span><span style="color: black;">咱们</span>的内功心法的。</span></p><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">热门内容:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><a style="color: black;">5种分布式事务<span style="color: black;">最后</span>一致性<span style="color: black;">处理</span><span style="color: black;">方法</span>,一次性说清了!</a></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><a style="color: black;">拜访了这位小哥的GitHub后,我失眠了!</a></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><a style="color: black;"><span style="color: black;">咱们</span><span style="color: black;">已然</span><span style="color: black;">不消</span>AOP做操作日志了!</a></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><a style="color: black;"><span style="color: black;">剧烈</span>不<span style="color: black;">意见</span>你用 a</a>.equals(b) 判断对象相等!</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">近期</span>面试BAT,整理一份面试资料</span><span style="color: black;">《<strong style="color: blue;">Java面试BAT通关手册</strong>》</span><span style="color: black;">,覆盖了Java核心技术、JVM、Java并发、SSM、微服务、数据库、数据结构等等。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">获取方式:点“</span><span style="color: black;">在看</span><span style="color: black;">”,关注公众号并回复 </span><span style="color: black;">666</span><span style="color: black;"> 领取,<span style="color: black;">更加多</span>内容<span style="color: black;">持续</span>奉上。</span></p><strong style="color: blue;">明天见(。・ω・。)ノ♡</strong>
论坛外链网http://www.fok120.com/ 可以发布外链的网站 http://www.fok120.com/ 回顾历史,我们感慨万千;放眼未来,我们信心百倍。
页:
[1]