docs(bg,en): fix ports and WebSocket example for new server model
CI / test (push) Has been cancelled
CI / verify (push) Has been cancelled
Clients CI / build-server (push) Has been cancelled
Clients CI / test-python (push) Has been cancelled
Clients CI / test-javascript (push) Has been cancelled
Clients CI / test-nim (push) Has been cancelled
Clients CI / test-rust (push) Has been cancelled

- Update architecture diagram to include WebSocket server (port 9913)
- Fix HTTP port from 9470 to 9912 (TCP + 440) in protocol docs
- Fix WebSocket port from 9471 to 9913 (TCP + 441) in protocol docs
- Fix WebSocket Nim example: remove non-existent onMessage API and
  unsafe cast[string](data), use correct WsServer API with safe helpers
- Clarify TCP_NODELAY is also handled internally by hunos (HTTP)
- Note that bytesToString/stringToBytes are wire-protocol helpers
This commit is contained in:
2026-05-18 19:41:21 +03:00
parent 8afa998516
commit 343f479127
4 changed files with 36 additions and 22 deletions
+10 -5
View File
@@ -45,15 +45,20 @@ TCP и HTTP сървърите споделят един LSMTree инстанс
├────────────────────────┬────────────────────────────────┤ ├────────────────────────┬────────────────────────────────┤
│ TCP Сървър │ HTTP Сървър │ │ TCP Сървър │ HTTP Сървър │
│ (Бинарен Протокол) │ (REST API) │ │ (Бинарен Протокол) │ (REST API) │
│ Порт: 9472 │ Порт: 9912 │ Порт: 9472 │ Порт: 9912 (TCP + 440)
│ TCP_NODELAY: ВКЛ │ Multi-threaded │ │ TCP_NODELAY: ВКЛ │ Multi-threaded │
────────────────────────┴──────────────────────────────── ────────────────────────┴────────────────────────────────
│ WebSocket Сървър │
│ (Streaming/Pub-Sub) │
│ Порт: 9913 (TCP + 441) │
│ TCP_NODELAY: ВКЛ │
└─────────────────────────────────────────────────────────┘
``` ```
**Ключови оптимизации:** **Ключови оптимизации:**
- **Споделен LSMTree** — И двата сървъра работят върху един и същ database инстанс, елиминирайки несъответствие в данните - **Споделен LSMTree** — Всички сървъри работят върху един и същ database инстанс, елиминирайки несъответствие в данните
- **TCP_NODELAY** — Включен както на слушащия, така и на клиентските сокети за по-ниска латентност при малки съобщения - **TCP_NODELAY** — Включен на слушащите и клиентските сокети в TCP/WebSocket сървърите за по-ниска латентност при малки съобщения. HTTP сървърът (чрез hunos) също управлява `TCP_NODELAY` вътрешно.
- **Безопасна конверсия на байтове** — Правилни `bytesToString`/`stringToBytes` функции вместо unsafe `cast` операции - **Безопасна конверсия на байтове** — Правилни `bytesToString`/`stringToBytes` функции вместо unsafe `cast` операции във wire протокола
### Управление на Връзки ### Управление на Връзки
+3 -3
View File
@@ -110,7 +110,7 @@ BaraDB поддържа множество протоколи за клиент
## HTTP/REST API ## HTTP/REST API
Базов URL: `http://localhost:9470/api/v1` Базов URL: `http://localhost:9912/api/v1` (HTTP порт = TCP порт + 440)
### Rate Limiting ### Rate Limiting
@@ -271,7 +271,7 @@ POST /admin/check
## WebSocket Протокол ## WebSocket Протокол
URL: `ws://localhost:9471` URL: `ws://localhost:9913` (WebSocket порт = TCP порт + 441)
### Формат на Frame ### Формат на Frame
@@ -301,7 +301,7 @@ WebSocket текстови frame-ове съдържат JSON съобщения
### Pub/Sub Пример ### Pub/Sub Пример
```javascript ```javascript
const ws = new WebSocket('ws://localhost:9471'); const ws = new WebSocket('ws://localhost:9913');
ws.onopen = () => { ws.onopen = () => {
// Абониране за промени в таблица // Абониране за промени в таблица
+10 -5
View File
@@ -45,15 +45,20 @@ The TCP and HTTP servers share a single LSMTree instance to ensure data consiste
├────────────────────────┬────────────────────────────────┤ ├────────────────────────┬────────────────────────────────┤
│ TCP Server │ HTTP Server │ │ TCP Server │ HTTP Server │
│ (Binary Protocol) │ (REST API) │ │ (Binary Protocol) │ (REST API) │
│ Port: 9472 │ Port: 9912 │ Port: 9472 │ Port: 9912 (TCP + 440)
│ TCP_NODELAY: ON │ Multi-threaded │ │ TCP_NODELAY: ON │ Multi-threaded │
────────────────────────┴──────────────────────────────── ────────────────────────┴────────────────────────────────
│ WebSocket Server │
│ (Streaming/Pub-Sub) │
│ Port: 9913 (TCP + 441) │
│ TCP_NODELAY: ON │
└─────────────────────────────────────────────────────────┘
``` ```
**Key optimizations:** **Key optimizations:**
- **Shared LSMTree** — Both servers operate on the same database instance, eliminating data inconsistency - **Shared LSMTree** — All servers operate on the same database instance, eliminating data inconsistency
- **TCP_NODELAY** — Enabled on both listening and client sockets for lower latency on small messages - **TCP_NODELAY** — Enabled on listening and client sockets in TCP/WebSocket servers for lower latency on small messages. The HTTP server (via hunos) also handles `TCP_NODELAY` internally.
- **Safe byte conversion** — Proper `bytesToString`/`stringToBytes` functions instead of unsafe `cast` operations - **Safe byte conversion** — Proper `bytesToString`/`stringToBytes` functions instead of unsafe `cast` operations in the wire protocol
### Connection Management ### Connection Management
+13 -9
View File
@@ -145,7 +145,7 @@ printf '\x00\x00\x00\x12\x01\x02\x00\x00\x00\x00\x08SELECT 1' > /dev/tcp/localho
## HTTP/REST API ## HTTP/REST API
Base URL: `http://localhost:9470/api/v1` Base URL: `http://localhost:9912/api/v1` (HTTP port = TCP port + 440)
### Rate Limiting ### Rate Limiting
@@ -321,7 +321,7 @@ POST /admin/check
## WebSocket Protocol ## WebSocket Protocol
URL: `ws://localhost:9471` URL: `ws://localhost:9913` (WebSocket port = TCP port + 441)
### Frame Format ### Frame Format
@@ -351,7 +351,7 @@ WebSocket text frames contain JSON messages:
### Pub/Sub Example ### Pub/Sub Example
```javascript ```javascript
const ws = new WebSocket('ws://localhost:9471'); const ws = new WebSocket('ws://localhost:9913');
ws.onopen = () => { ws.onopen = () => {
// Subscribe to table changes // Subscribe to table changes
@@ -403,7 +403,7 @@ let error = makeErrorMessage(1, 42, "Syntax error")
```nim ```nim
import barabadb/protocol/http import barabadb/protocol/http
var router = newHttpRouter(port = 9470) var router = newHttpRouter(port = 9912)
router.get("/api/users", proc(req: Request): Future[JsonNode] {.async.} = router.get("/api/users", proc(req: Request): Future[JsonNode] {.async.} =
return %*[ return %*[
@@ -422,11 +422,15 @@ router.post("/api/users", proc(req: Request): Future[JsonNode] {.async.} =
```nim ```nim
import barabadb/core/websocket import barabadb/core/websocket
var server = newWsServer(port = 9471) proc bytesToString(data: seq[byte]): string =
server.onMessage = proc(ws: WebSocket, data: seq[byte]) {.gcsafe.} = result = newString(data.len)
echo "Received: ", cast[string](data) for i in 0..<data.len:
asyncCheck ws.send(cast[string](data)) # Echo result[i] = char(data[i])
asyncCheck server.run()
var server = newWsServer(config, secretKey)
server.onInsert = proc(table, key, value: string) =
echo "Insert in ", table, ": ", key
asyncCheck server.run(9913) # WS port = TCP port + 441
``` ```
### Connection Pool ### Connection Pool