Skip to content
This repository was archived by the owner on Apr 11, 2019. It is now read-only.
This repository was archived by the owner on Apr 11, 2019. It is now read-only.

URL Fallback #6

@Highjhacker

Description

@Highjhacker

We need to have a list of valid peers and switch between them if the used one encounter issues.

I've tried a first solution for this problem :

    # More for the idea than anything else. Currently it should work, but the
    # Erlang beam crashed, telling the following message :
    # eheap_alloc: Cannot allocate 915463784 bytes of memory (of type "heap").
    def get_best_dev_peers do
      peers = get_dev("api/peers")
      peers["peers"]
      |> Enum.map(fn (x) -> %{ip: x["ip"], delay: x["delay"]} end)
      |> Enum.sort
      |> Enum.slice(0, 10)
    end
    def get_random_viable_peer do
      get_best_dev_peers()
      |> Enum.random
    end
    def get_ip_from_random_peer do
      get_random_viable_peer()
      |> Enum.at(1)
      |> elem(1)
    end

But as commented, the implementation doesn't seems good. The idea is to fetch the best peers (ordered by delay) and to make our queries on the peer choosed (with his IP as our url).

Then it would be easy to make our queries, and then fallback on the best peer chosen if the first one failed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions