*** sorry, completely failed to figure out how to post code here ... this post might not make much sense as is, sorry about that ***
Why does this program run 6 times more slowly in an Opalstack shell than it does in a free-tier GCP (google cloud platform) shell?
The program is so simple that there doesn't seem to be much scope for me to be doing something wrong, but it is always possible.
For each of the 149 email addresses in my account it prints a line of text giving the email address, the list of destinations, and the list of forwards.
On GCP it takes 80 secs, and in Opalstack it takes 520 secs.
As a point of reference, running it locally on Windows (with each API call going separately through a low-earth-orbit starlink connection) takes only a bit longer than Opalstack, at 615 secs.
#!/usr/bin/env python3
from requests.auth import AuthBase
import requests
import json
mytoken = "XXXXXX" # replace with your token
class TokenAuth(AuthBase):
def __init__(self, token):
self.token = token
def __call__(self, r):
r.headers['Authorization'] = f"Token {self.token}"
r.headers['Content-Type'] = "application/json"
return r
def jpiMailList ():
r = requests.get(f'https://my.opalstack.com/api/v1/address/list/',
auth=TokenAuth(mytoken))
return r.json()
def jpiMailRead (auid):
r = requests.get(f"https://my.opalstack.com/api/v1/address/read/{auid}",
auth=TokenAuth(mytoken))
return r.json()
def jpiMailuserRead (a):
r = requests.get(f"https://my.opalstack.com/api/v1/mailuser/read/{a}",
auth=TokenAuth(mytoken))
return r.json()
def destination2name (u):
return jpiMailuserRead (u)['name']
for i in jpiMailList ():
e = jpiMailRead (i['id'])
destinations = list (map (destination2name, e['destinations']))
print (f"{e['source']} : {', '.join (sorted (destinations))} ; {', '.join (sorted (e['forwards']))}")