You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. # crystal-scatter
  2. ## Installation
  3. Add this to your application's `shard.yml`:
  4. ```yaml
  5. dependencies:
  6. crystal-scatter:
  7. git: https://git.nekoit.xyz/Archivist/crystal-scatter
  8. version: ~> 0.1.0
  9. ```
  10. ## Usage
  11. ```crystal
  12. require "crystal-scatter"
  13. ```
  14. 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).
  15. ```crystal
  16. client_ip = "185.124.235.1"
  17. ring = Crystal::Scatter::MetaRing.new(3)
  18. ring.add [
  19. Crystal::Scatter::Daemon (8 , [0,0,0,0,0,0], "https://api01.myservice.com"),
  20. Crystal::Scatter::Daemon (16, [0,0,0,0,1,0], "https://api02.myservice.com"),
  21. Crystal::Scatter::Daemon (12, [1,0,0,0,0,0], "https://api03.myservice.com"),
  22. Crystal::Scatter::Daemon (12, [1,0,0,0,1,0], "https://api04.myservice.com"),
  23. Crystal::Scatter::Daemon (12, [2,0,0,0,0,0], "https://api05.myservice.com")
  24. ]
  25. ring.get_slices_for(client_ip)
  26. # => [
  27. # "https://api01.myservice.com",
  28. # "https://api03.myservice.com",
  29. # "https://api05.myservice.com"
  30. # ]
  31. ```
  32. The output will provide you information to contact the service in a balanced way.
  33. ## Contributing
  34. 1. [Fork it](https://git.nekoit.xyz/repo/fork/18)
  35. 2. Create your feature branch (`git checkout -b my-new-feature`)
  36. 3. Commit your changes (`git commit -am 'Add some feature'`)
  37. 4. Push to the branch (`git push origin my-new-feature`)
  38. 5. Create a new Pull Request
  39. ## Contributors
  40. - Ludovic 'Archivist' Lagouardette - creator, maintainer
  41. - [Gitea](https://git.nekoit.xyz/Archivist)
  42. - [Github](https://www.github.com/Zenohate)