Code Monkey home page Code Monkey logo

go-push's Introduction

go-push

用GO做推送

Dependency

  • golang.org/x/net/http2 (注: GFW已墙, 请到海外服务器下载)
  • github.com/gorilla/websocket

Arch

  • gateway: 长连接网关
    • 海量长连接按BUCKET打散, 减小推送遍历的锁粒度
    • 按广播/房间粒度的消息前置合并, 减少编码CPU损耗, 减少系统网络调用, 巨幅提升吞吐
  • logic: 逻辑服务器
    • 本身无状态, 负责将推送消息分发到所有gateway节点
    • 对调用方暴露HTTP/1接口, 方便业务对接
    • 采用HTTP/2长连接RPC向gateway分发消息

May be a problem

  • 推送主要瓶颈是gateway层而不是内部通讯, 所以gateway和logic之间仍旧采用了小包通讯(对网卡有PPS压力), 同时logic为业务提供了批量推送接口来缓解特殊需求.

Benchmark

environment

  • 16 vcore
  • client, logic, gateway deployed together

Bandwidth

bandwidth

Cpu Usage

cpu usage

API

全员广播

curl http://localhost:7799/push/all -d 'items=[{"msg": "hi"},{"msg": "bye"}]'

房间广播

curl http://localhost:7799/push/room -d 'room=default&items=[{"msg": "hi"},{"msg": "bye"}]'

Protocol

  • PING(upstream)
{"type": "PING", "data": {}}
  • PONG(downstream)
{"type": "PONG", "data": {}}
  • PUSH(downstream)
{"type": "PUSH", "data": {"items": [{"name": "go-push"}, {"age": "1"}]}}

go-push's People

Contributors

owenliang avatar

Watchers

 avatar  avatar

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.