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 @@ The TCP and HTTP servers share a single LSMTree instance to ensure data consiste
├────────────────────────┬────────────────────────────────┤
│ TCP Server │ HTTP Server │
│ (Binary Protocol) │ (REST API) │
│ Port: 9472 │ Port: 9912
│ Port: 9472 │ Port: 9912 (TCP + 440)
│ TCP_NODELAY: ON │ Multi-threaded │
────────────────────────┴────────────────────────────────
────────────────────────┴────────────────────────────────
│ WebSocket Server │
│ (Streaming/Pub-Sub) │
│ Port: 9913 (TCP + 441) │
│ TCP_NODELAY: ON │
└─────────────────────────────────────────────────────────┘
```
**Key optimizations:**
- **Shared LSMTree** — Both 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
- **Safe byte conversion** — Proper `bytesToString`/`stringToBytes` functions instead of unsafe `cast` operations
- **Shared LSMTree** — All servers operate on the same database instance, eliminating data inconsistency
- **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 in the wire protocol
### 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
Base URL: `http://localhost:9470/api/v1`
Base URL: `http://localhost:9912/api/v1` (HTTP port = TCP port + 440)
### Rate Limiting
@@ -321,7 +321,7 @@ POST /admin/check
## WebSocket Protocol
URL: `ws://localhost:9471`
URL: `ws://localhost:9913` (WebSocket port = TCP port + 441)
### Frame Format
@@ -351,7 +351,7 @@ WebSocket text frames contain JSON messages:
### Pub/Sub Example
```javascript
const ws = new WebSocket('ws://localhost:9471');
const ws = new WebSocket('ws://localhost:9913');
ws.onopen = () => {
// Subscribe to table changes
@@ -403,7 +403,7 @@ let error = makeErrorMessage(1, 42, "Syntax error")
```nim
import barabadb/protocol/http
var router = newHttpRouter(port = 9470)
var router = newHttpRouter(port = 9912)
router.get("/api/users", proc(req: Request): Future[JsonNode] {.async.} =
return %*[
@@ -422,11 +422,15 @@ router.post("/api/users", proc(req: Request): Future[JsonNode] {.async.} =
```nim
import barabadb/core/websocket
var server = newWsServer(port = 9471)
server.onMessage = proc(ws: WebSocket, data: seq[byte]) {.gcsafe.} =
echo "Received: ", cast[string](data)
asyncCheck ws.send(cast[string](data)) # Echo
asyncCheck server.run()
proc bytesToString(data: seq[byte]): string =
result = newString(data.len)
for i in 0..<data.len:
result[i] = char(data[i])
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