SNA
SNA

Reputation: 7728

Calling mutliple services in a method. How to do it effectively?

I have a asp .net web page(MVC) displaying 10,000 products.

For this I am using a method. In that method I have to call an external web service 20 times. This is because the web service gives me 500 data at a time, so to get 10000 data I need to call the service 20 times.

20 calls makes the page load slow. Now I need to increase the performance. Since web service is external I cannot make changes there.

Threading is an option I thought of. Since I can use page numbers (service is paging for the data) each service call is almost independent.

Another option is using parallel linq.

Should I use parallel linq, or choose threading?

Someone please guide me here. Or let me know another way to achieve this.

Note : this web page can be used by many users at a time.

We have filters left side of the page.for that we need all the 10,000 data to construct filter.Otherwise pagewise info could have been enough.and caching is not possible since the huge overload on the server. at a time 400-1000 users can hit server.web service response time is 10 second so that we can hit them many time

We have to hit the service 20 times to get all data.Now i need a solution to improve that hit.Is threading is the only option?

Upvotes: 0

Views: 122

Answers (3)

the_joric
the_joric

Reputation: 12261

Consider calling that service asyncrhonously. Most of delay in calling webservice is caused by IO operations that can be done simultaneously.

But getting 10000 items per each request is something very scarry :)

Upvotes: 0

mattmanser
mattmanser

Reputation: 5806

Threads, parallel linq will not help you here.

Parallel Linq is meant for lots of CPU work to be shared over CPU cores, what you want to do is make 20 web requests at the same time. You will need to use threading to do that.

You'll probably want to use the built in async capability of HttpWebRequest (see BeginGetResponse).

Upvotes: 0

starskythehutch
starskythehutch

Reputation: 3338

If you can't cache the data from the service, then just get the data you need, when you need to display it. I very much doubt that somebody wants to see all 10000 products on a single web page, and if they do, there is probably something wrong!

Upvotes: 2

Related Questions