Skip to content

perf: store geolocations of TES instances #130

Closed as not planned
Closed as not planned

Description

@uniqueg

Is your feature request related to a problem? Please describe.

The distance-based task distribution is quite slow. A major reason is that the geolocations for each TES instance are retrieved from a remote service, one by one, for each individual task, via a costly HTTP call.

Describe the solution you'd like

On the execution of the first task with the distance-based task distribution logic, fetch the geolocations of all TES instances from the remote service and store them in a dedicated database collection, using the host (e.g,. csc-tesk-noauth.rahtiapp.fi) as a key. Then, for any successive task, retrieve the geolocations of all TES instances in the list from the database collection with a single database call. Should there be any TES instances missing in the database (because they were added in the meantime; probably a rare occurence), fetch the missing geolocations from the remote service and add them to the database collection.

In this way, for the vast majority of calls, only input URI geolocations will need to be fetched from the remote service.

Describe alternatives you've considered

In addition to storing the geolocations of all encountered TES instances, it may be worthwhile to check if the geolocations for multiple input files can be fetched with a single request. This may further reduce the cost and limit the number of remote calls to one, even with multiple input files.

Updated scope (2026-10-22, migration plan)

  • The geolocation collection belongs to the distance-based middleware: it is created (via FOCA's config or on first use) only when the middleware is enabled, and not coupled to the task collection (see the comment of 2023-10-19).
  • Privacy: the middleware sends the IP addresses of input hosts (user data locations) and TES hosts to a third-party service (db-ip.com) for every task. Make the geolocation provider configurable, with an offline option (e.g. a local GeoIP database file), and document what is sent where.
  • Cache TES geolocations with an expiry, so moved instances are picked up.

Acceptance criteria

  • TES geolocations are looked up once per instance (until expiry), not per task; input geolocations as before or from the offline provider.
  • The provider is configurable, including an offline one; documented.
  • Tests cover the cache and the providers.

Activity

  1. added
    flag: good 1st issue
    priority: medium
    type: feature
    workload: hours
    on Mar 8, 2023
  2. uniqueg commented on Mar 8, 2023

    @uniqueg
    MemberAuthor

    Note that it is easy to set up another database collection via the FOCA-based app config used in proTES (it becomes basically a declarative issue).

  3. limarkdcunha commented on Mar 22, 2023

    @limarkdcunha

    Hi @uniqueg,I would to like to work on this issue but I have some doubts I would like to clear.
    As I understood, after the first call we need to store the  geolocations to the database and afterwards simply fetch them from the db.
    I am confused as to what is meant by first call here ? Is it first call of session initiated by a new user or the first call of day or of a particular timeframe. Knowing what a first call is will help simplify the process
    Also for "fetching the missing geolocations from the remote service and adding them to the database collection" when should one check if we have missing geolocations.

  4. uniqueg commented on Mar 22, 2023

    @uniqueg
    MemberAuthor

    Great, @limarkdcunha, please go ahead and assign yourself :)

    As for your question: Just check for every domain if it's in the database collection. If it is, then use the stored geolocations. If it isn't, follow the current procedure and then store them in the database collection. So for now let's assume all domain-coordinate pairs are stored in the database forever and are never updated once created (unless the database is wiped). This is of course not suitable for a production setting, but it's pretty much the same configuration we have for tasks, and we can worry about life cycle management for these documents later on.

    So you can just follow the way we are dealing with the tasks collection, including its registration via the app configuration in config.yaml that takes care of the boilerplate of setting up and configuring the collection.

  5. limarkdcunha commented on Mar 25, 2023

    @limarkdcunha

    Hi @uniqueg,thanks for the clarification.
    From what I understand from the codebase there are two task_distribution functions (random and distance).If the input urls are present in request ,distance based task_distribution is called or else random one is called.

    Random TD does nothing but reshuffles 5 domains present in the app context from config.yaml.Now here I am not able to figure out where are the geolocations fetched for a particular domain? As I am able to infer from create_task function of task_runs.py, url itself is used to create a task using tes.HTTPClient.

    Also in your first comment you said "In this way, for the vast majority of calls, only input URI geolocations will need to be fetched from the remote service". I find this statement a little confusing as I previously stated that without input_urls distance based task_distribution is not called.Can you please shed some light on this as well.
    A final thing I am not able to assign the issue to myself

  6. uniqueg commented on Mar 25, 2023

    @uniqueg
    MemberAuthor

    I have assigned you @limarkdcunha.

    Geolocations are only used for the distance-based distribution logic. The point is to choose a TES instance that is closest to the inputs. So if there are no inputs, it doesn't make sense to use it, and we just distribute tasks randomly. In that case, geolocations don't play a role.

    So geolocations are ONLY used in the distance-based task distribution logic, meaning that for addressing this issue, you will not need to look at the random distribution logic at all.

    Does that make it clear?

  7. limarkdcunha commented on Mar 26, 2023

    @limarkdcunha

    Yeah got it. Now I have good idea of what should be done.

  8. removed their assignment
    on Jul 28, 2023
  9. uniqueg commented on Oct 19, 2023

    @uniqueg
    MemberAuthor

    Mental note: Now that we provide the distance-based task distribution plugin (inside proTES, yet still apart), we need to think carefully how to set up the database so that it is not too tightly coupled with the main app db. Ideally, a collection for storing IP geolocations should be created automatically (and only) when the plugin is used.

  10. changed the title [-]Store geolocations of TES instances[/-] [+]perf: store geolocations of TES instances[/+] on Oct 22, 2026
  11. added
    type: security
    workload: days
    status: blocked
    and removed
    flag: good 1st issue
    workload: hours
    on Oct 22, 2026
  12. uniqueg commented on Oct 22, 2026

    @uniqueg
    MemberAuthor

    Still relevant, and scheduled with the middleware work at the end of the migration plan. I've added two points to the body: the collection belongs to the distance-based middleware (as noted above), and the geolocation provider becomes configurable, with an offline option, as the middleware currently sends the IP addresses of input and TES hosts to a third-party service for every task.

  13. uniqueg commented on Oct 23, 2026

    @uniqueg
    MemberAuthor

    One more thing to fix here: _get_ips in pro_tes/plugins/middlewares/task_distribution/distance.py passes urlparse(...).netloc to socket.gethostbyname. For URLs with a port, such as http://host:8080, the lookup fails and the task falls back to random distribution. urlparse(...).hostname would avoid that. This bug predates #214 (found while working on PR #245).

  14. uniqueg commented on Oct 31, 2026

    @uniqueg
    MemberAuthor

    Superseded: since #346 the distance-based routing is no longer part of proTES; it moves to foca-plugins (tes.routing.distance), whose cache of TES instance locations is elixir-cloud-aai/foca-plugins#21 (FOCA's plugin store, FOCA 0.19.0).

  15. removed
    status: blocked
    on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumtype: featuretype: securityworkload: days

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions