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

Slow down a little when getting items from the HackerNews API #4

Merged
merged 9 commits into from Jan 1, 2024

Conversation

davep
Copy link
Owner

@davep davep commented Jan 1, 2024

The HackerNews API is... fun. There's no way of saying "get me the data for all of these stories please", all you can do is get one at a time. I'd initially done this concurrently which was pretty bloody fast, but also meant that when it came to things like "Top" or "New", you were making at least 500 concurrent HTTP requests.

Yes, I agree, in 2024 this should not be a problem and we should be allow to spam API endpoints with no consequence. Apparently we're not there yet.

So, in an effort to behave better1, this PR adds a configurable limit on the number of concurrent connections, and also adds a higher and configurable timeout on the connections too.

Super huge thanks to @mihaitodor for being one of those awesome folk who runs into a problem, comments about it on HackerNews, and then goes and lets the developer know by filing an issue. That's some faith-in-humanity-restored-level-shit right there.

I guess there's hope for 2024 yet!

All of which is to verbosely say... I think this helps fix #2 for now (although a more lazy method of loading things into the UI might be something for me to switch to longer-term).

Footnotes

  1. In other words, do the thing I should have done to start with, if I wasn't paying way more attention to the UI rather than actually doing some proper coding on the tricky bits.

Due to the way the HackerNews API works, getting items is a bit of a pain.
There's no "get me the data for all these items please", it's "get me a list
of IDs and them make me load every single on individually". To start with I
just went all in on loading items up in parallel; which works fine for me
but, eh, there are some situations where 500 simultaneous HTTP requests is
a *bit* over the top (despite it being 2023! IKR?!?).

So, in an initial effort to explore solutions for #2 without leaning into
pagination, let's have a play with limiting the number of concurrent
connections and see what works.
@davep davep added bug Something isn't working enhancement New feature or request labels Jan 1, 2024
@davep davep self-assigned this Jan 1, 2024
@davep davep merged commit abd18e2 into main Jan 1, 2024
@davep davep deleted the be-more-chill-when-getting-stuff branch January 1, 2024 21:46
@mihaitodor
Copy link

mihaitodor commented Jan 2, 2024

awww
Thank you again for the quick fix! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timeout on start
2 participants