Distributed WebSocket Server

Related tags

Networking Keeper
Overview

Keeper

分布式 WebSocket 服务器。

注意事项

  • IO 线程和业务线程分离:对于小业务,依旧放到 worker 线程中处理,对于需要和中间件交互的丢到业务线程池处理,避免 worker 阻塞。
  • WebSocket 握手阶段支持参数列表。

插件

本服务功能插件化。

集群

project.plugin-config.enableCluster 属性决定是否启用 集群 模块。

project:
  plugin-config:
    enableCluster: true

如果启用集群模块,多个服务器将通过消息中间件同步消息,要求必须配置消息中间件。

用户

project.plugin-config.enableUser 属性决定是否启用 用户 模块。

project:
  plugin-config:
    enableUser: true

group

project.plugin-config.enableGroup 属性决定是否启用 群组 模块。

project:
  plugin-config:
    enableGroup: true

如果启用群组模块,则默认启用用户模块;否则以单机模式运行。

hearbeat

project.plugin-config.enableHearBeat 属性决定是否启用 心跳检测 模块,project.plugin-config.hearBeatCycle 控制心跳周期间隔时长,单位 s/秒。

project:
  plugin-config:
    enableHearBeat: false
    hearBeatCycle: 15

eventloop

project.plugin-config.enableEventLoop 属性决定是否启用 事件周期处理 模块,project.plugin-config.eventLoopCycle 控制事件处理周期间隔时长,单位 s/秒。

project:
  plugin-config:
    enableEventLoop: false
    eventLoopCycle: 15

环境配置需求

ulimit -n

Linux 对每个进程打开的文件句柄数量做了限制,如果超出:报错 "Too many open file"。

需要调大,如 65535,根据应用实际情况进一步调整。

堆内存

指定最小和最大堆大小,而且为了防止垃圾收集器在最小、最大之间收缩堆而产生额外的时间,通常把最大、最小设置为相同的值。

-Xms12G -Xmx12G

堆外内存

DirectByteBuffer 对象的回收需要依赖 Old GC 或者 Full GC 才能触发清理,我们需要通过 JVM 参数 -XX:MaxDirectMemorySize 指定堆外内存的上限大小,当堆外内存的大小超过该阈值时, 就会触发一次 Full GC 进行清理回收。

-XX:MaxDirectMemorySize=4G

一定要配置:-Xms、-Xmx 、-XX:MaxDirectMemorySize,它们的和不能超过 docker 的最大内存,否则当 docker 内存占满了会被 OOM kill。

G1

前台应用推荐使用 G1,G1 比 CMS 更适合大内存的垃圾收集。

-XX:+UseG1GC

使用 G1 时,不要使用 -Xmn、-XX:NewRatio 等其他相关显式设置年轻代大小的参数,它们会覆盖暂停时间的指标。

部署

Nginx 代理

location / {
    proxy_pass http://webscoket;
    proxy_set_header Host $host:$server_port;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

用 Nginx 反向代理某个业务,发现平均 1 分钟左右,就会出现 WebSocket 连接中断。 产生原因:Nginx 等待第一次通讯和第二次通讯的时间差,超过了它设定的最大等待时间,简单来说就是超时!

解决方法 1:

其实只要配置 nginx.conf 的对应 localhost 里面的这几个参数就好。

  • proxy_connect_timeout;
  • proxy_read_timeout;
  • proxy_send_timeout;
http {
    server {
        location / {
            root   html;
            index  index.html index.htm;
            proxy_pass http://webscoket;
            proxy_http_version 1.1;
            proxy_connect_timeout 4s;                #配置点1
            proxy_read_timeout 60s;                  #配置点2,如果没效,可以考虑这个时间配置长一点
            proxy_send_timeout 12s;                  #配置点3
            proxy_set_header Upgrade $http_upgrade; 
            proxy_set_header Connection "Upgrade";  
        }
    }
}

解决方法 2:

发心跳包,原理就是在有效地再读时间内进行通讯,重新刷新再读时间

proxy_read_timeout 这个参数是服务器对你等待最大的时间,也就是说当你 WebSocket 使用 Nginx 转发的时候,proxy_read_timeout 时间内没有通讯, 依然是会断开的,设置时间内有心跳或者有通信的话,是可以保持连接不中断的。

You might also like...

Book Finder application is a client-server application (gRPC) for educational purposes.

Book-Finder Book Finder application is a client-server application (gRPC) for educational purposes. Instalation These projects (Client/Server) are Mav

Oct 27, 2022

Realtime Client Server Framework for the JVM, supporting WebSockets with Cross-Browser Fallbacks

Realtime Client Server Framework for the JVM, supporting WebSockets with Cross-Browser Fallbacks

Welcome to Atmosphere: The Event Driven Framework supporting WebSocket and HTTP The Atmosphere Framework contains client and server side components fo

Jan 3, 2023

HTTP Server Model made in java

SimplyJServer HTTP Server Model made in java Features Fast : SimplyJServer is 40%-60% faster than Apache, due to it's simplicity. Simple to implement

Sep 25, 2021

Check the connectivity of a server with this API.

Check the connectivity of a server with this API.

ServerStatusAPI Presentation : This is a java API with which can test the conectivity of server (all server but you can also use for minecraft). The f

Mar 16, 2022

A small java project consisting of Client and Server, that communicate via TCP/UDP protocols.

A small java project consisting of Client and Server, that communicate via TCP/UDP protocols.

Ninja Battle A small java project consisting of Client and Server, that communicate via TCP/UDP protocols. Client The client is equipped with a menu i

Jan 14, 2022

A Velocity proxy plugin for Minecraft server discovery in k8s

A Velocity proxy plugin for Minecraft server discovery in k8s. All discovered servers are automatically added to the Velocity proxy.

Sep 13, 2022

A cross-server spigot plugin that simulate market economy

A cross-server spigot plugin that simulate market economy

Aug 21, 2022

Microhttp - a fast, scalable, event-driven, self-contained Java web server

Microhttp is a fast, scalable, event-driven, self-contained Java web server that is small enough for a programmer to understand and reason about.

Dec 23, 2022

FileServer - A multithreaded client-server program that uses Java Sockets to establish TCP/IP connection

A multithreaded client-server program that uses Java Sockets to establish TCP/IP connection. The server allows multiple clients to upload, retrieve and delete files on/from the server.

Nov 13, 2022
Owner
岚
A Java event based WebSocket and HTTP server

Webbit - A Java event based WebSocket and HTTP server Getting it Prebuilt JARs are available from the central Maven repository or the Sonatype Maven r

null 808 Dec 23, 2022
WebSocket server with creatable/joinable channels.

bytesocks ?? bytesocks is a WebSocket server which allows clients to create "channels" and send messages in them. It's effectively an add-on for byteb

lucko 6 Nov 29, 2022
Asynchronous Http and WebSocket Client library for Java

Async Http Client Follow @AsyncHttpClient on Twitter. The AsyncHttpClient (AHC) library allows Java applications to easily execute HTTP requests and a

AsyncHttpClient 6k Dec 31, 2022
Magician is an asynchronous non-blocking network protocol analysis package, supports TCP, UDP protocol, built-in Http, WebSocket decoder

An asynchronous non-blocking network protocol analysis package Project Description Magician is an asynchronous non-blocking network protocol analysis

贝克街的天才 103 Nov 30, 2022
A simple, fast integration of WebSocket spring-stater

websocket-spring-boot-starter readme 介绍 一个简单,快速,低配的spring-boot-starter,是对spring-boot-starter-websocket的扩展与二次封装,简化了springboot应用对websocket的操作 特点 简单,低配 支

Jack 4 Dec 24, 2021
A simple Discord bot, which shows the server status of the Lost Ark server Beatrice

Beatrice A simple Discord bot, which shows the server status of the Lost Ark server Beatrice. Example Usage Clone the repository. Edit the property fi

Leon 3 Mar 9, 2022
Chaos engineering tool for simulating real-world distributed system failures

Proxy for simulating real-world distributed system failures to improve resilience in your applications. Introduction Muxy is a proxy that mucks with y

Matt Fellows 811 Dec 25, 2022
TCP/UDP client/server library for Java, based on Kryo

KryoNet can be downloaded on the releases page. Please use the KryoNet discussion group for support. Overview KryoNet is a Java library that provides

Esoteric Software 1.7k Jan 2, 2023
Socket.IO server implemented on Java. Realtime java framework

Netty-socketio Overview This project is an open-source Java implementation of Socket.IO server. Based on Netty server framework. Checkout Demo project

Nikita Koksharov 6k Dec 30, 2022
BAIN Social is a Fully Decentralized Server/client system that utilizes Concepts pioneered by I2P, ToR, and PGP to create a system which bypasses singular hosts for data while keeping that data secure.

SYNOPSIS ---------------------------------------------------------------------------------------------------- Welcome to B.A.I.N - Barren's A.I. Natio

Barren A.I. Wolfsbane 14 Jan 11, 2022