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 line
1.7 KiB

6 年之前
6 年之前
6 年之前
6 年之前
6 年之前
6 年之前
6 年之前
  1. # crystal-scatter
  2. Release candidate for v0.1 "John Scott"
  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: ~> 0.1.0-rc2
  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 , [0,0,0,0,0,0], "https://api01.myservice.com"),
  21. Crystal::Scatter::Daemon (16, [0,0,0,0,1,0], "https://api02.myservice.com"),
  22. Crystal::Scatter::Daemon (12, [1,0,0,0,0,0], "https://api03.myservice.com"),
  23. Crystal::Scatter::Daemon (12, [1,0,0,0,1,0], "https://api04.myservice.com"),
  24. Crystal::Scatter::Daemon (12, [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. ## Contributing
  35. 1. [Fork it](https://git.nekoit.xyz/repo/fork/18)
  36. 2. Create your feature branch (`git checkout -b my-new-feature`)
  37. 3. Commit your changes (`git commit -am 'Add some feature'`)
  38. 4. Push to the branch (`git push origin my-new-feature`)
  39. 5. Create a new Pull Request
  40. ## Contributors
  41. - Ludovic 'Archivist' Lagouardette - creator, maintainer
  42. - [Gitea](https://git.nekoit.xyz/Archivist)
  43. - [Github](https://www.github.com/Zenohate)