locked
Memory and CPU usage of my asp.net app on azure RRS feed

  • Question

  • User-2097295820 posted

    Please I need advice. I have uploaded my web application on my web server. currently all I am doing is testing. But I notice that the memory usage seems to be quite high. I am not running any background process. I used lot of stored procedures to speeding up my db calls. I would paste a screen shot. Please kindly help me interpret. If it is too high advice on things I need to look out for in my code that could be using memory. There is currently no traffic on this app. I don't think there is any reason for a high usage at the moment.

    0.03 HOURS
    -------------------------------------------------------------------------------------------------------------------------------------------------------
    CPU TIME (RESETS IN 24 HOURS)                                                                                                               1% of 4 HOURS/DAY


    0.24 MINUTES
    -------------------------------------------------------------------------------------------------------------------------------------------------------
    CPU TIME - MINUTE LIMIT (RESETS IN 5 MINUTES)                                                                                       8% of 3 MIN/5 MINS

    135.82 MB
    -------------------------------------------------------------------------------------------------------------------------------------------------------
    FILE SYSTEM STORAGE                                                                                                                                27% of 1024 MB

    279.98 MB
    ---------------------------------------------------------------------------------------------------------------------------------------------------------
    MEMORY USAGE (RESETS IN 1 HOUR)                                                                                                        27% of 1024MB / HOUR

    Thursday, February 18, 2016 2:14 PM

All replies

  • User541108374 posted

    Hi,

    are you not closing your connections perhaps? Make use of the using statement where possible to cleanup. Also reduce the amount of information you keep in session per user and think about making use of caching via Redis in Azure. You might also want to move static files to a CDN for example.

    With Application Insights you could try to track down what's causing a high memory usage.

    Also check out http://stackoverflow.com/questions/3405557/asp-net-website-memory-usage-quite-high.

    Grz, Kris.

    Thursday, February 18, 2016 2:31 PM
  • User-2097295820 posted

    I would paste an example of the repository class below. Maybe I am not closing db object well. I did not use the using () statement because I am  implementing the IDisposable

    So I disposed my context object in my Dispose(). When I used using () on my context in my code. I got some errors like context is already closed in areas when I am calling multiple db methods.

    So I allow my Dispose() method to clear my context after the class obj has been called. This is a sample of my repository class

        public class AdvertSettingRepository : IAdvertSettingRepository, IDisposable
        {
            //Declaring the variables of the repository
            private DatabaseContext context = null;
            private bool disposed = false;
    
            public AdvertSettingRepository() {
    
                context = new DatabaseContext();
            }
    
    
            public async Task<int> Savesetting(AdvertSetting setting)
            {
                int result = 0;
    
                try
                {
                    context.AdvertSettings.Add(setting);
                    result = await context.SaveChangesAsync();
                }
                catch(Exception e){
                    result = 0;
                }
    
                return result;
            }
    
    
            protected virtual void Dispose(bool disposing)
            {
                if (!this.disposed)
                {
                    if (disposing)
                    {
                        context.Dispose();
                    }
                }
    
                this.disposed = true;
            }
    
            public void Dispose()
            {
                Dispose(true);
                GC.SuppressFinalize(this);
            }
    
        }
    }

    Thursday, February 18, 2016 2:58 PM
  • User-2097295820 posted

    HI Bro, I still observing my app. I have a filling that it my resources that is consuming memory. because even when there are no traffic on the app. The memory usage 269.58 MB.

    So I don't think It is a database object not been disposed well because you can take a look at my database class if you notice any issue let me know. I also made a few trafffic on the site. I notice a very little difference in memory change.

    After a few clicks which I used to test just to see database memory usage memory increased to 276.36 MB just a little difference. So what is taking up the initial 269.58 MB

    My application is very large the raw codes is 510 MB. Then I am not using much of sessions. I only use sessions onces in the application. so it is not sessions. I thinking that it is static files that is been loaded in the memory. I dont know. But please kindly look at my db codes and let me know if you see something abormal in the way I close connection. Thank you.

    Thursday, February 18, 2016 4:03 PM
  • User541108374 posted

    Hi,

    I would also try to lazy instantiate the context by making use of the Lazy<T> class: https://msdn.microsoft.com/en-us/library/dd642331(v=vs.110).aspx. Or if you need it multiple times in different repositories instantiate it on a higher level and pass it in to the constructor of the repository IoC style.

    After a few clicks which I used to test just to see database memory usage memory increased to 276.36 MB just a little difference. So what is taking up the initial 269.58 MB

    Ok so it's not spiking a lot then it seems. I suggest you take it out of the Free tier on Azure and see how it behaves for a couple of hours (costs will incur then) and put Load Testing on it (you can set that up on Azure as well) and simulate a ramping up from 1 to 1000 users and look at the memory usage then.

    Be sure to check if the application is not set to debug mode = true in your config as that might also hurt performance.

    Grz, Kris.

    Friday, February 19, 2016 7:36 AM
  • User-2097295820 posted

    Thaanks alot, I just noticed that my web config is in debug mode. Which I corrected. Performance on the app is increased. Well concerning the  lazy instantiate, it might be a bit of a challenge because I have a lot of repositories in my application. The application is now in SHARD. I am trying to getting some users to use the application so I see how it works. Though I forgot to mention that signalr is running on this application. Or could it be signalr that is using the application memory even when app is in idle state.

    Friday, February 19, 2016 2:53 PM
  • User541108374 posted

    Hi,

    for SignalR: did you turn on web sockets? If not then do so or you'll fall into the backup technologies to make things work like long polling or so which might cause perf issues.

    Grz, Kris.

    Friday, February 19, 2016 2:59 PM
  • User-2097295820 posted

    I tried a Load test on the App for 250 users. Kindly see the response below

    AVG Resp Time -  1.5s

    Req/Sec - 608.01

    - In space of 5 mins

    ON THE WEB APP, it hosted on Shared hosting for websites

    CPU - 118 % (OVER CAPACITY)

    Memory Usage - (566.88 mb)

    My App used up 55% of 1024 mb

    Friday, February 26, 2016 12:30 PM
  • User541108374 posted

    Hi,

    1.5 seconds seems quite slow. Is this a first non cached retrieval of the page or a "hot" page.

    What if you put it on dedicated hosting (not shared)?

    Grz, Kris.

    Tuesday, March 1, 2016 9:54 AM
  • User-2097295820 posted

    It hot page. In fact it the landing page of the web app. The page itself does not do any database call before loading. It does a db fetch but I did that with an ajax call. Maybe I might resort to using CDN because the only thing that could make it slow is the images on the landing page.

    Though images are not heavy cause total page size resorts to 580k.

    I would try dedicated hosting and is it in action ?

    Tuesday, March 1, 2016 2:42 PM