Archivist b53de6cc2b | пре 6 година | |
---|---|---|
spec | пре 6 година | |
src | пре 6 година | |
.editorconfig | пре 6 година | |
.gitignore | пре 6 година | |
.travis.yml | пре 6 година | |
LICENSE | пре 6 година | |
README.md | пре 6 година | |
shard.yml | пре 6 година |
Release candidate for v0.1 "John Scott"
Add this to your application's shard.yml
:
dependencies:
crystal-scatter:
git: https://git.nekoit.xyz/Archivist/crystal-scatter
version: ~> 0.1.0-rc2
require "crystal-scatter"
Create a MetaRing and add services to it, using the weights as a mark of the load the service can handle (example: number of threads each CPU of the servers can handle).
client_ip = "185.124.235.1"
ring = Crystal::Scatter::MetaRing.new(3)
ring.add [
Crystal::Scatter::Daemon (8 , [0,0,0,0,0,0], "https://api01.myservice.com"),
Crystal::Scatter::Daemon (16, [0,0,0,0,1,0], "https://api02.myservice.com"),
Crystal::Scatter::Daemon (12, [1,0,0,0,0,0], "https://api03.myservice.com"),
Crystal::Scatter::Daemon (12, [1,0,0,0,1,0], "https://api04.myservice.com"),
Crystal::Scatter::Daemon (12, [2,0,0,0,0,0], "https://api05.myservice.com")
]
ring.get_slices_for(client_ip)
# => [
# "https://api01.myservice.com",
# "https://api03.myservice.com",
# "https://api05.myservice.com"
# ]
The output will provide you information to contact the service in a balanced way.
Crystal::Scatter::Daemon (12, [2,0,0,0,0,0], "https://api05.myservice.com")
^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | |
| | | | | | | L Real target
| | | | | | L Serving daemon
| | | | | L Serving server
| | | | L Serving PSU
| | | L Serving rack
| | L Serving room
| L Serving datacenter
L Weight
Such information is to be supplied to Crystal::Scatter
.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)