Apache License 2.0

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

SweelRT 项目深度技术分析

项目背景与痛点

SwellRT 是一个专注于实时协作的项目,集中在为 Web 应用提供实时的协同编辑服务。在现代 Web 应用中,实时协作是一项关键功能,无论是文档编辑、代码编辑还是多人在线游戏,都需要高效且实时的协同处理机制。SwellRT 通过简化协作流程,减少同步延迟,以及提供可靠的同步机制,极大提升了多用户协作的效率和体验。

在当前的协同编辑领域,传统的中心化架构难以满足实时性与可靠性的要求。SwellRT 采用分布式架构设计,有效解决了同步延迟和数据一致性的问题,使得协作场景更加自然且实时。

核心技术揭秘

架构与实现原理

SwellRT 的架构分为三个主要部分:服务器、JavaScript 客户端和 Java 客户端。服务器作为数据同步的中心点,负责维护共享状态并提供实时更新;客户端负责与服务器的实时通信,从而实现多用户间的同步编辑。

如下图所示,系统通过高效的数据流与协议传输,确保每个客户端的数据更新都能够即时传播到其他客户端。

graph LR A[客户端A] --> B[服务器] C[客户端B] --> B D[客户端C] --> B B --> A B --> C B --> D

客户端与服务器之间的通信主要使用了 WebSocket,使得多用户实时编辑数据的同步成为可能。服务器端则采用了 MongoDB 作为数据存储层,保证了高可用性和数据的一致性。此外,SwellRT 引入了 CRDT(Conflict-free Replicated Data Type)算法,解决多用户同时编辑时的冲突问题。

功能亮点与差异

SwellRT 在实现实时协同时,通过引入 CRDT 算法,解决了同步过程中常见的数据冲突问题。相较于传统的锁定机制和冲突解决机制,CRDT 在无需中心化协调的情况下,能高效地实现多个客户端同时更新同一数据。

此外,SwellRT 还支持多种编程语言,如 JavaScript 和 Java 客户端。这使得开发者能够在多种编程环境中进行开发与集成,极大地增强了项目的可移植性和易用性。该特性在处理不同平台和设备间的协作时显得尤为重要。

应用场景与落地建议

在生产环境中使用 SweelRT 时,需要特别关注服务器的性能和稳定性。无论是高并发用户请求还是数据同步的耗时,都需要通过优化算法和合理配置来提升系统性能。此外,安全性和数据隐私也至关重要,确保通信中的数据加密和安全认证机制是非常必要的。

SwellRT 适用于各种需要实时协作的应用场景,如在线文档编辑、多人编程协作、在线协同绘图、实时报告生成等。无论是大型企业还是小型创业团队,SwellRT 都能提供高效、可靠的技术支持。

综合评价

优点

  1. 实时性:采用 CRDT 算法,确保多用户实时编辑的同步性。
  2. 可靠性:通过 WebSocket 实现多客户端通讯,可支撑高并发场景。
  3. 多语言支持:提供 JavaScript 和 Java 客户端,便于多平台开发集成。

缺点

  1. 性能需求:高并发场景下对服务器资源和性能要求较高。
  2. 数据量承载:CRDT 在处理大量数据同步时可能导致性能瓶颈。

SwellRT 作为一款致力于实时协作的工具,展现出了其在多用户协同编辑方面的强大能力。通过其创新的技术架构和多语言支持,SwellRT 在未来的信息协同中将起到更加重要的作用。

关于

GitHub 原始描述(英文)

SwellRT main project. Server, JavaScript and Java clients

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

Batchfile
CSS
Dockerfile
HTML
Java
JavaScript
Shell
Smalltalk

Release

README

SwellRT Build Status Gitter

SwellRT is an open source backend-as-a-service. It provides prebuilt features to speed up development of collaborative Web applications:

  • Realtime storage (eventual consistency)
  • Extensible text collaborative editor
  • User management and authentication
  • Server federation with Matrix
  • Events and Bots (in development)

The main feature of SwellRT is realtime storage based in objects. They can be shared among participants that can mutate them in realtime. All changes are persisted and propagated transparently. Object’s state is eventually consistent.

Check out API basics:


service.open({

	id: '<object-id>'

}).then(object => {

 	// Anyone can open the object
	object.setPublic(true);

});

Set and get a property:


object.set('person', 
  { 
	name: 'Alice',
	city: 'New York'
  });
  
object.get('person.city');

  

Listen for updates (local or remote):


object.node('person').addListener( event => {
	
	console.log('Property Updated ');

});	

Client libraries for Web and Java/Android (experimental) are provided.

Documentation and examples

API documentation can be found here

Basic examples can be found here. Try them running a SwellRT server and visiting http://localhost:9898

Running a SwellRT Server

You can build the server yourself or use our pre-built Docker image.

Building SwellRT from source code

Prerequisites

Clone the project

git clone [email protected]:SwellRT/swellrt.git
cd swellrt

Build

./gradlew compileJava devWeb

If you get a “User limit of inotify watches reached” error, please increase this limit following stesp here

Start the server

./gradlew run

Visit http://localhost:9898 to check server installation and try some demos.

Standalone installation (Jar)

To create a standalone installation of SwellRT, use the createDistBinTar or createDistBinJar tasks:

./gradlew createDistBinJar

The generated file is placed at distributions/ folder. Extracts the file and use the run-server.sh or run-server.bat scripts to start the server.

Edit configuration in config/wave.conf based on config/reference.conf.

Docker

Get docker image of SwellRT (latest version by default). Check out all available SwellRT versions at Docker Hub:

$ docker pull p2pvalue/swellrt

Run docker container in deattached mode (-d).

$ docker run \ 
-e MONGODB_HOST=<host> \
-e MONGODB_PORT=<port> \
-e MONGODB_DB=<db name> \
-p 9898:9898 \
-h swellrt \
--name swellrt \
-d p2pvalue/swellrt

This commands also binds default SwellRT server port 9898, to port 9898 in the host machine (-p 9898:9898). Sets hostname to “swellrt” (-h). And configures SwellRT to use a MongoDB server instance with the provided parameters.

See following section to configure a MongoDB instance.

Persistent folders

For productive installations of SwellRT, config and data folders should be outside the container. For example, to put all log files in host’s folder /var/log/swellrt, run docker with -v parameter:

$ docker run -v /usr/local/swellrt/log:/var/log/swellrt  -p 9898:9898 -h swellrt -d p2pvalue/swellrt

These are all the folders you can map outside the container:

Folder (Docker cointainer) Description
/usr/local/swellrt/config Server config files
/usr/local/swellrt/log Server log files
/usr/local/swellrt/sessions Persistent HTTP Sessions
/usr/local/swellrt/avatars Users avatar images
/usr/local/swellrt/attachments User files

Server config

Server configuration can be adjusted by editing files in the config/ folder. Default settings can be found in the repo.

If you map the config/ folder in your host machine, you must copy those files to it.

Post installation

Visit “http://localhost:9898” and “http://localhost:9898/chat” to check server installation and try some demos.

MongoDB

This section explains how to install and configure a MongoDB server with SwellRT.

Get latest MongoDB Docker image

$ docker pull mongo

Run mongo container

$ docker run -p 27017:27017 --name mongo -d mongo

Run SwellRT (it assumes Docker containers are using default bridge network)

$ docker run \
-e MONGODB_HOST=172.17.0.1 \
-e MONGODB_PORT=27017 \
-e MONGODB_DB=swellrt \
-p 9898:9898 \
-h swellrt \
--name swellrt \
-d p2pvalue/swellrt

The database swellrt is created automatically if it doesn’t exist.

Federation

SwellRT servers can be federated using Matrix protocol. A set up guide and technical documentation can be found here.

Contact and Support

Visit our Gitter Channel or email to [email protected].

Java/Android client

An experimental Java library is in package org.swellrt.beta.client.platform.java Check out chat demo app in *org.swellrt.beta.client.platform.java.ChatDemo".

Contributing

Read our contributing guide to learn more about our development process, how to propose bugfixes and improvements, and how to build and test your changes to SwellRT.

Acknowledgments

The SwellRT project is a fork of Apache Wave. Initial work of SwellRT has been funded by the EU research project P2Pvalue and supported by GRASIA research group of the Universidad Complutense of Madrid.

Cryptographic Software Notice

This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country’s laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See http://www.wassenaar.org/ for more information.

The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms. The form and manner of this Apache Software Foundation distribution makes it eligible for export under the License Exception ENC Technology Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for both object code and source code.

The following provides more details on the included cryptographic software:

Wave requires the BouncyCastle Java cryptography APIs: http://www.bouncycastle.org/java.html

评论

暂无评论