Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a service API using ASP.NET MVC 4 and Web API and I need to handle shipping stored in a database images.

My intention was to manage lists, ie put all the images, you can return me a query, a list of type string, for this I make the array of bytes to get from the query image and transform a string using Convert. ToBase64String.

So making a single request, the Web Service returns me the list to the client and manage images displayed in an application. The detail here is that I realized that there is a maximum limit of memory you can use an application (I'm not sure when I just do not allow many images) and can not always send all images in a list.

So I came up image by image by sending a request by each, but what if there are 20 pictures to send ?, 20 requests would be made; and if they are 10 users who need to download information 20 images each, would be 200 requests.

My question is, what will happen to the server, collapse or what ?, how correct is the way I'm using for sending images, lists (although I do not think it serves me well) or image ?, Why would I do if taking 10 of the 20 files downloaded to the network connection is lost ?, Is there a way to do this without so many requests? and if someone can explain to me how the webservice as to be used or IIS problem (which incidentally I'm using it to publish the web service) resources.
Posted

1 solution

Depends on your server's hardware, it wouldn't collapse. It is not a wormhole, but a machine. It will simply get slow, think of it like having a water pipe with capacity to allow 5 litres of water and you try to get 20 litres of it? Will it collapse? No, it will provide you with 20 litres of water but will take 4 times the actual time required.

Again, the problem you are referring to is a widely ignored problem. 20 images are 20 requests, and that will cause the server to slow down. Ever wondered why? The "why" is the overhead data such as headers and response generation etc. If you create a single connection, establish it and stream the data over it (like sockets), then it won't be a bigger problem. Got the idea?

Now, let me dissect it down into pieces. The only solution here is to cut short the requests, one method I have already told you. You are using a Web Service, create a client and download all images in a single request.

1. Either perform a bulk download.
- In this method, you can create a huge byte array of the data of images, like a JSON notation then convert it to images.
2. ZIP the images, download the archive, open the archive and use them. ZIP would also decrease the size of the images. 1 MB may be 0.95 MB (save each and every second you can!)

These are just a few of the tips that I can give. Among others, there are many with a great use:

1. Cut short the number of images being streamed down. User is never going to see all 20 images in a snap. He would be watching at most 5, so download 5. Then allow user to click on a button to download next and so on and so forth.
2. Increase the RAM and CPU cores. So that no matter how many requests come, your server always has a new thread available to handle the request.
- Servers get slow because there are no more processes or threads available to handle the request. Thus slowing down the response time.
- Make sure there are threads available! Either by adding more hardware resources.
3. Consider using asynchronous programming model[^]. In this model, most of the work will be done in a background normal thread, so your request handling thread will be left free for other new requests. Asynchronous programming model would be my choice, it doesn't need more hardware, but just a complex model.

HTTP/2[^] is active nowadays (I am not sure whether as a standard or not but) IIS 10 supports it and most browsers also support HTTP/2. Which provides you with ability to compress headers, perform other features. But it is not yet implemented, so do not count on this.
 
Share this answer
 
Comments
Member 11318373 24-Sep-15 11:23am    
thank you. I have now a clearer idea of how the work requests and I will consider your recommendations
Afzaal Ahmad Zeeshan 24-Sep-15 11:48am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900