pybitcash / bitcash

BitCash: Python Bitcoin Cash Library (fork of ofek's Bit)
https://bitcash.dev
MIT License
97 stars 39 forks source link

Reuse HTTP connections #109

Closed sajal closed 2 years ago

sajal commented 2 years ago

Reuse http/https connections to speed-up requests and reduce load on client and server.

Currently each time the library needs to make a request, it makes a fresh TCP+TLS connection to the remote server, then do the request, then discard the TCP+TLS connection.

With this change, once a request has been done, the connection goes into an idle connection pool. then next time you want to make a request, it would take the previously established connection and reuse it.

For example, our backend is in France, and user is in Thailand having a round trip time of ~300ms. it would take minimum ~900ms for client to make a request and get a response.

Now if client does a get_balance and then broadcast_tx. In current code it would take minimum ~1800ms (900ms + 900ms) to do both requests

With this change it would take minimum ~1200ms (900ms + 300ms) since we don't need to re-initialize a new connection.

I have not tested this change.