Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7695011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:26:56+00:00 2026-05-31T21:26:56+00:00

I’m developing a web service using ASP.NET MVC3. One of the methods of the

  • 0

I’m developing a web service using ASP.NET MVC3.
One of the methods of the HTTP API receives an image from the body of a POST request and needs to store it on the disk for further processing.
The beginning of the method is like this:

Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();

Interlocked.Increment(ref _generateCount);

byte[] fileBuffer;
using (Stream inputStream = Request.InputStream)
{
    if (inputStream.Length == 0)
    {
        Trace.WriteLine("Submitted file is empty", "Warning");
        inputStream.Close();
        Interlocked.Decrement(ref _generateCount);
        return new HttpStatusCodeResult(400, "Content is empty");
    }

    fileBuffer = new byte[inputStream.Length];
    inputStream.Read(fileBuffer, 0, (int)inputStream.Length);
    inputStream.Close();
}
stopwatch.Stop()
... (storing the fileBuffer on disk & quite CPU intensive processing on the file)

I’m hosting the service in a small Azure instance.

Now the strange behavior I have is when I issue parallel requests to the service.
Let’s say I issue a first request, and a second one 5 seconds later. As you see I’m using a Stopwatch to monitor the performance. For the first request, the ElapsedTime will be very small (less than one second) but for the second one, it usually reads approx. 14 seconds!

Note that the average processing time for a single request is approx. 25 seconds (and gets to 40+ when multiple requests are being processed), so I get my input stream read 14 seconds later, although the first request hasn’t finished.

How can I explain this delay ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:26:58+00:00Added an answer on May 31, 2026 at 9:26 pm

    If your final goal is to store the file on the disk why are you loading it in-memory? You could directly write to the output stream:

    public ActionResult SomeAction()
    {
        var stopwatch = Stopwatch.StartNew();
        if (Request.InputStream.Length == 0)
        {
            return new HttpStatusCodeResult(400, "Content is empty");
        }
    
        var filename = Server.MapPath("~/app_data/foo.dat");
        using (var output = System.IO.File.Create(filename))
        {
            Request.InputStream.CopyTo(output);
        }
        stopwatch.Stop();
    
        ...
    }
    

    Also notice that if you issue 2 concurrent requests that attempt to write to the same file on your server, you might get corrupted data or errors as you cannot write to the same file at the same time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.