Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port exhaustion #18

Closed
dave4you opened this issue Jul 15, 2020 · 0 comments · Fixed by #195
Closed

Port exhaustion #18

dave4you opened this issue Jul 15, 2020 · 0 comments · Fixed by #195

Comments

@dave4you
Copy link

dave4you commented Jul 15, 2020

Current implementation causes port exhaustion. This can be solved implementing urllib3 PoolManager. Implementing this prevents opening a new port for every http request. This means less processor overhead and 30% time winst.

#Add
from urllib3 import PoolManager

class SubstrateInterface:

    def __init__

                #Add 
                self.http = PoolManager()


    def rpc_request(self, method, params):

                else:

#previous: response = requests.request("POST", self.url, data=json.dumps(payload), headers=self.default_headers)
response = self.http.request("POST", self.url, body=json.dumps(payload), headers=self.default_headers)

#previous: if response.status_code != 200:
if response.status != 200:
                              #previous: raise SubstrateRequestException("RPC request failed with HTTP status code {}".format(response.status_code ))
raise SubstrateRequestException("RPC request failed with HTTP status code {}".format(response.status))

#previous: json_body = response.json()
json_body = json.loads(response.data.decode('utf-8'))`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant