Teleport2.0 a new framework for Golang TCP sockets

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Teleport beta2.0 implements a new Golang TCP socket frame, which is versatile, efficient and flexible! Can be used for peer-peer peering, RPC, long connection gateway, microservices, push services, gaming services and other fields.


Teleport_server

1. Features

    • Peer communication between server and client, the API method is basically the same
    • The underlying communication packet consists Header of Body two parts
    • Supports individual customization Header and Body encoding types, such as JSONProtobuf
    • BodySupports gzip compression
    • HeaderContains the status code and its description text
    • Support Push, pull, reply and other communication methods
    • Support plug-in mechanism, you can customize the authentication, heartbeat, micro-service registry, statistical information plug-ins.
    • Graceful reboot, graceful shutdown regardless of server or client
    • Support for reverse proxy functionality
    • Detailed log information, support print input, output message details (status code, message header, message body)
    • Support for setting the slow-action alarm threshold value
    • The underlying connection uses I/O buffers
    • Inter-endpoint communication using I/O multiplexing technology

AB testing 1: [Mac 4CPU 8GB] [single-process single-conn] Teleport:qps 37550


Teleport_frame_client_ab_test

AB Testing 2: [Mac 4CPU 8GB] [single-process single-conn] Teleport/socket:qps 55419


Teleport_socket_client_ab_test

2. Architecture

2.1 Name Explanation

    • Peer: Communication Endpoint, possibly client or client
    • Session : connect sessions, with push, pull, reply, close and other operations
    • Context: processing received or sent packets
    • pull-launch: pull data from peer peers
    • pull-handle: processing and replying to a pull request to peer
    • push-launch: pushing data to peer peers
    • push-handle: handling Peer push
    • Router: Handler registering a route

2.2 Level of execution

Peer -> Connection -> Socket -> Session -> Context

2.3 Data Packets

HeaderLength | HeaderCodecId | Header | BodyLength | BodyCodecId | Body

Attention:

    • Headerlength:uint32, 4 bytes, big endian
    • Bodylength:uint32, 4 bytes, big endian
    • Headercodecid:uint8, 1 byte
    • Bodycodecid:uint8, 1 byte
type Packet struct {    // HeaderCodec header codec name    HeaderCodec string `json:"header_codec"`    // BodyCodec body codec name    BodyCodec string `json:"body_codec"`    // header content    Header *Header `json:"header"`    // body content    Body interface{} `json:"body"`    // header length    HeaderLength int64 `json:"header_length"`    // body length    BodyLength int64 `json:"body_length"`    // HeaderLength + BodyLength    Length int64 `json:"length"`}

2.4 Head Information

type Header struct {    // Packet id    Id string    // Service type    Type int32    // Service URI    Uri string    // Body encoding type    Gzip int32    // As reply, it indicates the service status code    StatusCode int32    // As reply, it indicates the service status text    Status string}

3. Open Source Project

Project Address: Https://github.com/henrylee2cn/teleport
License Agreement: Apache2.0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.