0

I am using PubMed api and the first request is quite slow. When performing a simple curl request such as curl -X GET "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?" it takes around 7s.

So I made an experiment and when using python request Session the requests after the first one take 0.3 seconds on average that is great!

s = requests.Session()
url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?"
timeout = 20
headers = {'User-agent': 'Mozilla/5.0'}
for query in queries: # a list of 10 queries
    response = requests.get(url=url, headers=headers, timeout=timeout)
    print(response.text)

The example above looks great, with the exception of the first query. So the idea was to use a flask api and ping it every 3 seconds to keep the API warm.

The flask file looks like:

app = Flask(__name__)

s = requests.Session()
url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?"
timeout = 20
headers = {'User-agent': 'Mozilla/5.0'}

@app.route('/', methods=["GET"])
def query_pubmed():
    query = request.args.get('query')
    params = params,
    response = s.get(url=url, timeout=timeout, params=params, headers=headers)
    return json.dumps({'response': response.text})


app.run()

I run it on a server and ensured to ping it every few second, but I did not get the wanted result. Every request takes 6-7 seconds to return an answer as if every time it was the first time.

Is there a way to maintain the API warm towards PubMed's endpoint?

purple_lolakos
  • 456
  • 5
  • 15

0 Answers0