Giter VIP home page Giter VIP logo

keeplearning's Issues

详解websocket之一--通信原理

场景一:
John正在开发一个社区论坛项目,其中有一个需求,需要在前端页面添加一个通知面板,用来实时展示通知信息,比如@某某评论了您的帖子,@某某关注了您,您关注的@某某发表了新的主题帖。John采用了ajax请求轮询方案来实现,首先注册一个定时器,每隔一段时间去调用后端一个接口去获取通知信息。功能上线后,平稳运行。某天论坛的同时在线人数达到峰值,由于服务器配置较低,大量的轮询请求直接导致服务器瘫痪。
场景二:
Kristin正在做一个云计算平台,创建虚拟机是这个平台的一个基本功能,由于虚拟机的创建流程较长,创建接口被设计成异步请求。用户发起创建请求后,立即返回201,告知用户创建正在执行中。待虚拟机创建完成后,需要再次通知用户创建是否成功。但此时由于请求已经结束,无法再次将消息进行反馈。Kristin同样采用了轮询的方案,为了降低服务器的压力,Kristin加大了轮询的时间间隔,但是通知的及时性确被降低了,用户反馈使用体验很不友好。

HTTP协议
缺点:

  1. 实时性低,延迟时间=轮询间隔+通信延迟。
  2. 效率低,客户端不得不发起大量的无用请求。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.