Skip to content

Fix: federation requests timeout - #24

Merged
syphax-bouazzouni merged 11 commits into
developmentfrom
fix/federation-requests-timeout
Feb 3, 2025
Merged

syphax-bouazzouni merged 11 commits into
developmentfrom
fix/federation-requests-timeout

Conversation

@Bilelkihal

@Bilelkihal Bilelkihal commented Jan 9, 2025 •

Copy link
Copy Markdown

Related issue: agroportal/ontoportal_web_ui#889

Problem Description

The current implementation of the get method has a timeout set to 60 seconds. This creates a significant delay in cases where a portal (e.g., BiodivPortal) is down because multiple requests are sent for a single operation. For example:

1 - If BiodivPortal is down, selecting it on the browse page triggers multiple requests to its API endpoints (e.g., /ontologies, /submissions, /categories, etc.).
2 - Each request waits for the full 60-second timeout before failing.
3 - This results in compounded delays, causing the user to wait for several minutes before receiving feedback.

Proposed solution in this PR

To address this issue, this PR introduces the following improvements:

  • When the first request to a portal (e.g., BiodivPortal) times out, the system caches the "portal down" status for 10 minutes.
  • Subsequent requests to the same portal within this cache period will be skipped, avoiding unnecessary delays.
  • The request timeout is reduced from 60 seconds to 20 seconds.

Result

  • If a portal is down, the total wait time for the user is 20 seconds before getting the message: "The portal ... is down".

Demo

Fully explained in browse page (enable sound)
https://drive.google.com/file/d/13JAVRZradprsXNjwmhJj_AMA58WwTTYr/view?usp=sharing

Screenshot from search page
image

@Bilelkihal Bilelkihal self-assigned this Jan 9, 2025
@Bilelkihal Bilelkihal added the bug label Jan 9, 2025

@Bilelkihal Bilelkihal left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅

Comment thread lib/ontologies_api_client/request_federation.rb
Comment thread lib/ontologies_api_client/request_federation.rb
@syphax-bouazzouni

syphax-bouazzouni commented Jan 9, 2025 •

Copy link
Copy Markdown

The demo video was nice

@jonquet

jonquet commented Jan 9, 2025

Copy link
Copy Markdown

Quick question: can you leave the time out at 60s and do only one call if the first one fails. I mean, you go to the 2 other calls only of the first one doe snot times out.

@Bilelkihal

Copy link
Copy Markdown
Author

we decided today to keep the timeout 30s

@Bilelkihal

Copy link
Copy Markdown
Author

@syphax-bouazzouni Tests working now, ready to be merged

Comment thread test/models/test_federation.rb
Comment thread Gemfile Outdated
Comment thread Gemfile Outdated
gem 'test-unit'
gem 'webmock', require: false No newline at end of file
gem 'webmock', require: false
gem 'activesupport', '~> 7.0.8' No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to add this as it is already added in the gemspec file

module Client
module RequestFederation

CACHE = ActiveSupport::Cache::MemoryStore.new

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not work as expected as in the Rails we don't use MemoryStore, but MemeCache or Redis.

@Bilelkihal

Copy link
Copy Markdown
Author

@syphax-bouazzouni Finally I initialized a fake Rails.cache in the tests envirenment that uses ActiveSupport::Cache::MemoryStore.new so the tests are running while the UI is working as supposed also.

@syphax-bouazzouni syphax-bouazzouni left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants