Skip to content

Reading table with URL is doing many requests - #2001

Merged
embray merged 1 commit into
astropy:masterfrom
taldcroft:io-ascii-2001
Nov 28, 2014
Merged

embray merged 1 commit into
astropy:masterfrom
taldcroft:io-ascii-2001

Conversation

@taldcroft

Copy link
Copy Markdown
Member

If I read a web-based CSV file using requests it works straightaway and quickly:

In [62]: weather_url
Out[62]: 'http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1'

In [63]: dat = Table.read(requests.get(weather_url).text, format='ascii')

But if I do what I think is the equivalent directly with Table.read it's hitting the site many times and takes probably 10 times as long:

In [64]: dat = Table.read(weather_url, format='ascii')
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]

In [65]: 

@astrofrog

Copy link
Copy Markdown
Member

Huh, that's not good!

@taldcroft

Copy link
Copy Markdown
Member Author

I haven't looked at how it works, but I ran the commands again (this time in master, not 0.3) and it seems like there is maybe a default timeout that is too short. Using master, after trying ~10 times it actually gave a timeout exception.

@embray

embray commented Jan 27, 2014

Copy link
Copy Markdown
Member

Why would the log message read "[Done]" if the request was actually timing out, or is that an oversight too? :)

@pllim

pllim commented Jan 27, 2014

Copy link
Copy Markdown
Member

I did it a slightly different way and did not see such behavior. FYI.

>>> import astropy
>>> astropy.__version__
'0.3'
>>> from astropy.table import Table
>>> from astropy.utils.data import get_file_contents
>>> dat = Table.read(get_file_contents(weather_url), format='ascii')
Downloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statenamDownloading http://www.wunderground.com/history/airport/KLAS/2010/3/1/CustomHistory.html?dayend=28&monthend=4&yearend=2010&req_city=NA&req_state=NA&req_statename=NA&format=1 [Done]

@astrofrog astrofrog modified the milestones: v0.4.1, v0.3.3 May 9, 2014
@astrofrog astrofrog modified the milestones: v0.4.1, v0.3.3 May 21, 2014
@embray embray modified the milestones: v0.4.2, v0.4.3 Sep 23, 2014
@embray

embray commented Nov 24, 2014

Copy link
Copy Markdown
Member

I double checked and it seems this is still an issue. My guess (pun not intended) is that it's due to the guessing process in io.ascii, except it's downloading the file every time instead of using a cached copy. @pllim's version works because by using get_file_contents it's just returning the table as a string and it's reusing that string each time.

@taldcroft

Copy link
Copy Markdown
Member Author

Code attached. I haven't read the get_readable_fileobj code carefully, but my assumption is that if you don't pass something that can be turned into a readable file object (e.g. a list of data lines) that it just throws an exception. I'm using that to just always try to get a readable file object from the input table when guessing (except for CDS format). This passes io.ascii tests and seems reasonable.

@embray - you were right about this being related to guessing.

cc: @hamogu

@taldcroft taldcroft self-assigned this Nov 25, 2014
@embray

embray commented Nov 25, 2014

Copy link
Copy Markdown
Member

I don't really understand the fix, but it works for me so 👍

@hamogu

hamogu commented Nov 27, 2014

Copy link
Copy Markdown
Member

This is a good way to do it (I think I can say that after spending significant time on get_file_contents and guessing last week, when I tried to debug why python3 and python2 gave different results when reading from a file object).

So 👍 to merging this.

Just for the record: Not all CDS tables have a separate readme object. Some might have the readme on top of the file and those would go through get_file_contents. However, for those CDS tables that is the right way to do it.

embray added a commit that referenced this pull request Nov 28, 2014
Reading table with URL is doing many requests
@embray
embray merged commit 68bd605 into astropy:master Nov 28, 2014
embray added a commit that referenced this pull request Dec 31, 2014
Reading table with URL is doing many requests
@taldcroft
taldcroft deleted the io-ascii-2001 branch February 25, 2019 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants