Skip to content

Create persistent HTTP connection for REST connections #140

Open
@ronnie-llamado

Description

@ronnie-llamado

Currently a new connection is opened on every HTTP interaction (see log output below). Introducing a requests.session tied to APIConnection and TigerConnection objects may show some performance gains, especially on larger transactions.

The main difference would amount to changing from requests.get to self.session.get (inside APIConnection and TigerConnection).

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.census.gov:443
DEBUG:urllib3.connectionpool:https://api.census.gov:443 "GET /data/2017/acs/acs5/variables.json HTTP/1.1" 200 664592
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.census.gov:443
DEBUG:urllib3.connectionpool:https://api.census.gov:443 "GET /data/2017/acs/acs5/geography.json HTTP/1.1" 200 1274
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.census.gov:443
DEBUG:urllib3.connectionpool:https://api.census.gov:443 "GET /data/2017/acs/acs5/tags.json HTTP/1.1" 200 312
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.census.gov:443
DEBUG:urllib3.connectionpool:https://api.census.gov:443 "GET /data/2017/acs/acs5/examples.json HTTP/1.1" 200 1946
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): tigerweb.geo.census.gov:443
DEBUG:urllib3.connectionpool:https://tigerweb.geo.census.gov:443 "GET /arcgis/rest/services/TIGERweb?f=json HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): tigerweb.geo.census.gov:443
DEBUG:urllib3.connectionpool:https://tigerweb.geo.census.gov:443 "GET /arcgis/rest/services/TIGERweb/tigerWMS_ACS2017/MapServer?f=json HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): tigerweb.geo.census.gov:443
DEBUG:urllib3.connectionpool:https://tigerweb.geo.census.gov:443 "GET /arcgis/rest/services/TIGERweb/tigerWMS_ACS2017/MapServer/layers?f=json HTTP/1.1" 200 None

If done, this will require some refactoring of remote.py and tiger.py. Perhaps even a BaseClass that can be shared between the two.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions