• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..18-Oct-2021-

tntengine/H18-Oct-2021-1,8871,631

tntserver/H18-Oct-2021-453378

main.goH A D18-Oct-20215.5 KiB204172

readme.mdH A D18-Oct-20212.6 KiB11271

readme.md

1This example shows how to use custom engine implementation based on [Tarantool](https://www.tarantool.io/en/): i.e. it provides `Broker` and `PresenceManager`.
2
3Tarantool provides faster history and presence operations than Redis (up to 10x), while being on pair in subscribe and publish performance.
4
5**Important limitation to know**: Tarantool Broker uses channels that start with `__` (two underscores) for internal needs and does not allow subscribing on them from the outside.
6
7Tarantool Broker PUB/SUB can be customized to work over PUSH or POLL.
8
9**Since this is just an example – we do not guarantee any stability here**. This implementation have not been tested in production environment.
10
11## Single Tarantool instance example
12
13Go to `tntserver` dir and install `indexpiration` rock dependency:
14
15```
16tarantoolctl rocks install https://raw.githubusercontent.com/moonlibs/indexpiration/master/rockspecs/indexpiration-scm-1.rockspec
17```
18
19Create a directory for Tarantool `snap` and `xlog` files:
20
21```
22mkdir tnt1
23```
24
25Start Tarantool:
26
27```
28tarantool init.lua 1
29```
30
31In another terminal start chat application running the following command from example directory:
32
33```
34go run main.go
35```
36
37Go to http://localhost:8000. You will see simple chat app, try writing a chat message in one browser tab – you should see it appears in another tab.
38
39## Client-side sharding
40
41Go to `tntserver` dir and create directories for Tarantool files:
42
43```
44mkdir tnt1
45mkdir tnt2
46```
47
48Start first Tarantool instance:
49
50```
51tarantool init.lua 1
52```
53
54Then second one:
55
56```
57tarantool init.lua 2
58```
59
60Now run first application instance on port 8000:
61
62```
63go run main.go --port 8000 --sharded
64```
65
66The second one on port 8001:
67
68```
69go run main.go --port 8001 --sharded
70```
71
72Go to http://localhost:8000 or http://localhost:8001 – nodes will be connected over Tarantool and data is consistently sharded between 2 different Tarantool instances (by a channel).
73
74## Tarantool high availability example
75
76Run Tarantool with leader-follower setup with Cartridge (using `127.0.0.1:3301` and `127.0.0.1:3302`). Then start application example:
77
78```
79go run main.go --port 8000 --ha
80```
81
82## Tarantool Raft high availability example
83
84**Requires Tarantool 2.6.1+ since example uses Raft-based replication**.
85
86Create directories for Tarantool files inside `tntserver` folder:
87
88```
89mkdir ha_tnt1 ha_tnt2 ha_tnt3
90```
91
92Run Tarantool cluster:
93
94```
95docker-compose up
96```
97
98Then start application:
99
100```
101go run main.go --port 8000 --ha --raft
102```
103
104At this moment you can temporary stop/run one of Tarantool instances using:
105
106```
107docker-compose pause tnt1
108docker-compose unpause tnt1
109```
110
111See that chat application continues to work after a short downtime.
112