Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

78 wiersze
2.5 KiB

  1. # crystal-scatter
  2. Release candidate for v1.0 "David Robert Jones"
  3. ## Installation
  4. Add this to your application's `shard.yml`:
  5. ```yaml
  6. dependencies:
  7. crystal-scatter:
  8. git: https://git.nekoit.xyz/Archivist/crystal-scatter
  9. version: ~> 1.0.0-rc1
  10. ```
  11. ## Usage
  12. ```crystal
  13. require "crystal-scatter"
  14. ```
  15. 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).
  16. ```crystal
  17. client_ip = "185.124.235.1"
  18. ring = Crystal::Scatter::MetaRing.new(3)
  19. ring.add [
  20. Crystal::Scatter::Daemon (8 , uuid01, [0,0,0,0,0,0], "https://api01.myservice.com"),
  21. Crystal::Scatter::Daemon (16, uuid02, [0,0,0,0,1,0], "https://api02.myservice.com"),
  22. Crystal::Scatter::Daemon (12, uuid03, [1,0,0,0,0,0], "https://api03.myservice.com"),
  23. Crystal::Scatter::Daemon (12, uuid04, [1,0,0,0,1,0], "https://api04.myservice.com"),
  24. Crystal::Scatter::Daemon (12, uuid05, [2,0,0,0,0,0], "https://api05.myservice.com")
  25. ]
  26. ring.get_slices_for(client_ip)
  27. # => [
  28. # "https://api01.myservice.com",
  29. # "https://api03.myservice.com",
  30. # "https://api05.myservice.com"
  31. # ]
  32. ```
  33. The output will provide you information to contact the service in a balanced way.
  34. ### In details
  35. ```crystal
  36. Crystal::Scatter::Daemon (12, uuid, [2,0,0,0,0], "https://api05.myservice.com")
  37. ^ ^ ^ ^ ^ ^ ^ ^ ^
  38. | | | | | | | | |
  39. | | | | | | | | L Real target
  40. | | | | | | | L Serving daemon
  41. | | | | | | L Serving server
  42. | | | | | L Serving PSU
  43. | | | | L Serving rack
  44. | | | L Serving room
  45. | | L Serving datacenter
  46. | L UUID provided by the HARP wrapper
  47. L Weight
  48. ```
  49. Such information is to be supplied to `Crystal::Scatter`.
  50. ## Contributing
  51. 1. [Fork it](https://git.nekoit.xyz/repo/fork/18)
  52. 2. Create your feature branch (`git checkout -b my-new-feature`)
  53. 3. Commit your changes (`git commit -am 'Add some feature'`)
  54. 4. Push to the branch (`git push origin my-new-feature`)
  55. 5. Create a new Pull Request
  56. ## Contributors
  57. - Ludovic 'Archivist' Lagouardette - creator, maintainer
  58. - [Gitea](https://git.nekoit.xyz/Archivist)
  59. - [Github](https://www.github.com/Zenohate)