Git Product home page Git Product logo

Comments (2)

hrafnl avatar hrafnl commented on September 28, 2024 1

Your arguments are convincing enough for me!

from themoviedbwrapper.

nCubed avatar nCubed commented on September 28, 2024

From what I can gather, the general recommendation is to have a single instance of HttpClient shared per endpoint. However, most of the recommendations are when dealing with high-load clients; for example, an MVC Controller or Web API endpoint with hundreds (thousands) of concurrent users resulting in hundreds/thousands of requests per second.

In this case, the HttpClient is specifically targeting themoviedb.org's API which is throttled at 40 requests per 10 seconds; this value seems to be hit and miss where sometimes it allows more, sometimes less. Given that the maximum number of allowed requests to themoviedb.org's API is extremely low, creating an HttpClient per request is the least resistant path forward.

I believe a better long-term approach would be to create a single shared HttpClient wrapped in some type of throttling queue to prevent receiving the error of "request count is over the allowed limit".

I have done performance profiling against TheMovieDbWrapper and the CreateClient() call is barely a blip on the timeline. The bottlenecks are on Newtonsoft's side for DeserializeObject. Here's a high-level breakdown when performing 40 calls to IApiMovieRequest.SearchByTitleAsync() and excludes all time allotted for waiting, i.e., async/await wating:

Percentage Root Method
24.8% Newtonsoft.Json.JsonConvert.DeserializeObject(String, JsonSerializerSettings)
13.9% System.ComponentModel.Composition.Hosting.ExportProvider.GetExportCore(String)
2.5% DM.MovieApi.MovieDb.Movies.ApiMovieRequest.SearchByTitleAsync(String, Int32, String)
0.62% DM.MovieApi.ApiRequest.ApiRequestBase.CreateClient()

Unless you are seeing a specific bottleneck, I'd like to keep the base class as-is for now.

from themoviedbwrapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.