Joystream / joystream

Joystream Monorepo
http://www.joystream.org
GNU General Public License v3.0
1.42k stars 115 forks source link

Identify operator selection policy by Atlas #5027

Closed ignazio-bovo closed 6 months ago

ignazio-bovo commented 8 months ago

SSIA. It's not clear yet how exactly Atlas identifies distributor nodes, especially when geolocation data is missing

ignazio-bovo commented 8 months ago

Video Player

scope: detail how videos are fetched in atlas in the video player page view, that is once I am on the home page and then I click on any of the video suggested

Stack Trace

1.GetFullVideo query is called. The fragment contains several fields among which a media.resolvedUrls.

  1. The distributor node url list is put together in this function here and they are sorted by user geographical proximity if user location data is available, otherwise they are randomly sorted. userLocation available in the Application tab > Local Storage > gleev.xyz on developer tools of most browsers
  2. The resolvedUrls are passed to the VideoComponents and eventually passed to useGetAssetUrl. The part where the logic select the right distributor node + asset for the react component is where the resolvedUrl variable is initialized via useSingleAssetUrl
  3. the useSingleAssetUrl runs orderly through every distribution url and for each construct a testAssetDownload promise. Subsequently select the first url that resolves that promise before a specific timeout. If no url is able to satisfy the timeout time constraint then it select the first url that resolve the promise constructed previously. the testAssetDownload when the asset is of type video if probes the url by sending a HEAD request and resolving when the first byte is received

TLDR Distribution url selection for videos

  1. URLs for a video are sorted either by geographical proximity to the user if geolocation is provided otherwise they are randomly sorted
  2. The final url for the streaming is selected as the closest (in the geographical sense) whose sampled time to first byte is less than a specified timeOut. If none of the url is able to provide a time to first byte lower than the timeOut value then the distribution node that is able to provide the lowest sampled time to first byte

Thumbnails

scope: detail how video thumbnails are fetched in atlas Since for each asset a sequence of resolvedUrl is similarly fetched, the process for image asset is identical in terms of DN urls choice

kdembler commented 8 months ago

@ignazio-bovo I think we still need to look into those timeouts logic. I have seen problematic behaviour on slow connections where Atlas kept switching provider, not giving any single URL enough time to load. This most likely resulted in worse UX if it just waited a bit longer for the first URL to load

ignazio-bovo commented 8 months ago

From the source code if none of the url is resolved within a specified timeout, then the first url to resolve is used The timeout value default value is here

kdembler commented 8 months ago

Yeah but from my experience on bad connection, the logic could be improved. If let's say video needs 500ms to start playing, but timeout gets set at 400ms, then Atlas will try X URLs for 400ms resulting in X * 400ms wait for the user, but if it just waited a bit longer, it would be only 500ms.