Skip to content

Commit e6aa196

Browse files
committed
Enhance Owlery client with retry logic for connection resets and add connectivity tests in performance workflow
1 parent be5a95a commit e6aa196

2 files changed

Lines changed: 42 additions & 15 deletions

File tree

.github/workflows/performance-test.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ jobs:
2828
python -m pip install --upgrade pip
2929
python -m pip install --upgrade -r requirements.txt
3030
python -m pip install -e . # Editable install ensures we test the actual source code
31+
32+
- name: Test Owlery Connectivity
33+
run: |
34+
echo "Testing basic connectivity to Owlery server..."
35+
curl -v --max-time 30 "http://owl.virtualflybrain.org/kbs/vfb/subclasses?object=%3Chttp%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FFBbt_00005106%3E&direct=false&includeDeprecated=false&includeEquivalent=true" | head -20 || echo "Simple query failed or timed out"
36+
echo ""
37+
echo "Testing if server responds at all..."
38+
curl -v --max-time 10 "http://owl.virtualflybrain.org/" || echo "Server unreachable"
3139
3240
- name: Run Performance Test
3341
run: |

src/vfbquery/owlery_client.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,26 @@ def convert_short_form_to_iri(match):
107107
'object': iri_query,
108108
'direct': 'false', # Always use indirect (transitive) queries
109109
'includeDeprecated': 'false', # Exclude deprecated terms
110-
'includeEquivalent': 'true', # Include equivalent classes
111-
'prefixes': json.dumps({
112-
"FBbt": "http://purl.obolibrary.org/obo/FBbt_",
113-
"RO": "http://purl.obolibrary.org/obo/RO_",
114-
"BFO": "http://purl.obolibrary.org/obo/BFO_"
115-
})
110+
'includeEquivalent': 'true' # Include equivalent classes
116111
}
117112

118113
# Make HTTP GET request with longer timeout for complex queries (20 minutes for OWL reasoning)
119-
response = requests.get(
114+
# Add retry logic for connection resets (common with long-running queries)
115+
from requests.adapters import HTTPAdapter
116+
from urllib3.util.retry import Retry
117+
118+
session = requests.Session()
119+
retry_strategy = Retry(
120+
total=3, # Total number of retries
121+
backoff_factor=2, # Wait 2s, 4s, 8s between retries
122+
status_forcelist=[500, 502, 503, 504], # Retry on server errors
123+
allowed_methods=["GET"] # Only retry GET requests
124+
)
125+
adapter = HTTPAdapter(max_retries=retry_strategy)
126+
session.mount("http://", adapter)
127+
session.mount("https://", adapter)
128+
129+
response = session.get(
120130
f"{self.owlery_endpoint}/subclasses",
121131
params=params,
122132
timeout=1200
@@ -211,13 +221,7 @@ def convert_short_form_to_iri(match):
211221
params = {
212222
'object': iri_query,
213223
'direct': 'true' if direct else 'false',
214-
'includeDeprecated': 'false',
215-
'prefixes': json.dumps({
216-
"FBbt": "http://purl.obolibrary.org/obo/FBbt_",
217-
"RO": "http://purl.obolibrary.org/obo/RO_",
218-
"BFO": "http://purl.obolibrary.org/obo/BFO_",
219-
"VFB": "http://virtualflybrain.org/reports/VFB_"
220-
})
224+
'includeDeprecated': 'false'
221225
}
222226

223227
# Build full URL for debugging
@@ -228,7 +232,22 @@ def convert_short_form_to_iri(match):
228232
print(f"Owlery instances URL: {prepared_request.url}")
229233

230234
# Make HTTP GET request to instances endpoint (20 minutes for OWL reasoning)
231-
response = requests.get(
235+
# Add retry logic for connection resets (common with long-running queries)
236+
from requests.adapters import HTTPAdapter
237+
from urllib3.util.retry import Retry
238+
239+
session = requests.Session()
240+
retry_strategy = Retry(
241+
total=3, # Total number of retries
242+
backoff_factor=2, # Wait 2s, 4s, 8s between retries
243+
status_forcelist=[500, 502, 503, 504], # Retry on server errors
244+
allowed_methods=["GET"] # Only retry GET requests
245+
)
246+
adapter = HTTPAdapter(max_retries=retry_strategy)
247+
session.mount("http://", adapter)
248+
session.mount("https://", adapter)
249+
250+
response = session.get(
232251
f"{self.owlery_endpoint}/instances",
233252
params=params,
234253
timeout=1200

0 commit comments

Comments
 (0)