ASP.NET MVC page slow Time To First Byte - asp.net-mvc-4

I have two views that I am refreshing every few seconds asp.net mvc. Every few views are refreshed since there is another program that is updating the database. It is taking a lot of time and it is random, what I mean by that is sometimes the first view reload time is slow and sometimes the second view reload time is slow. It is in 500ms or 50ms each for view1 and view2 or vice versa 500ms for view2 and 60ms for view1. I needs to reduce both the load time to 10ms. I have set the timer interval to 30 seconds and loading the views. I did sql profiler to see if the queries are taking a long time and it does not look like it. In dev tools TTFB time is showing as taking long and this is on my local machine with local webserver and sql. Please advise!
Thanks

Related

BigQuery view appears to be generating huge number of Queries

I have a View which is populated by a SQL request to a regular dataset. As far as I know, not a soul is looking at that view (at least not very often). But if I go to the View and click on Project History then there is an IAM service account which is running the query every 15 seconds. Each query is shuffling 2.55 MB and reading 70,000 records, so I'd really prefer that it didn't do this.
The dataset source to create the view shows that it's last modified date was 3 days ago, so the service account is not being trigged by a change in the source. I checked the job scheduler and nothin there. So what is triggering it and how can I tell it to calm down?

ASP.NET pages lag intermittently

I'm using IIS 10, SQL Server 14, and .NET 4.5. I have made a website with just 4 pages of significance. Any one of them loads perfectly, every time. And quickly, even though they do a lot of work with datatables and database edits.
But if I open two browser windows (same session if it matters) and play around for a while loading pages in one window while the other is refreshing another of the pages every 3 seconds, it is only a matter of time until they freeze up for a bit. Sometimes only for 5 or 10 seconds. Often for over a minute, and sometimes for as long as 20 minutes.
What I've tried:
My first thought was SQL deadlock and I spent a long time down that rabbit hole. All my select statements now use WITH (NOLOCK). I've run SQL profiler, and there is no discernible rhyme or reason to which queries have long durations during these periods, and none are that long. The longest "StartTime - EndTime" on the trace is never more than 0.25 seconds. I added my own StopWatch control to my functions that do my cmd.ExecuteNonQuery() statements and another on the one that gets my datatables, and see the same thing: max elapsed times during the hangs of 250ms or thereabouts. Under "normal" lag/hang-free operation, the elapsed times typically record 0ms, and at most maybe 3ms. The jump of 100x during the hang is confusing and concerning, but don't at all account for the long periods of lag/hang. And each time this happens, it will only be 1 or 2 statements with that extended duration.
I turned my attention to debugging the page that refreshes every 3 seconds. I use a StopWatch there also, and the page always loads in under 3ms as measured from the first line of the form_load event to the last line of the form_unload event. What is interesting here, is that while it is hung, it sure LOOKS LIKE Chrome (my browser) is trying to load the page. The little circle is spinning, and it is just waiting. It never times out, even if it takes 20 minutes. But during that time it will never record the first debug entry of form_load. Once it finally resolves, it will run the page as well as ever. So in my log I'll see something like this (oldest entry at the bottom):
2021-02-07 11:52:21.703 unload
2021-02-07 11:52:21.700 load
2021-02-07 11:52:18.642 unload
2021-02-07 11:52:18.640 load
2021-02-07 11:50:37.820 unload
2021-02-07 11:50:37.817 load
2021-02-07 11:50:34.777 unload
2021-02-07 11:50:34.773 load
Note how the page loads quickly every time, and while there is normally a 3 second gap between loads, in one case there was almost a 2 minute gap.
Looking at my W3SVC1 logs, and lining it up to that same time, I see that there are entries (both POST and GET) for the pages with time-taken of around 90000 (not sure what units on that) where the entries before and after the problem are mostly in the 10-50 range.
I'm at a loss of what to look at next.

SQL Query perform slow with increasing users

I have an asp.net web application with SQL server 2014 express database. My application runs well until data entry records are less, but as the data entry records saving increases, not every time but sometime page takes too long to load back again. On save button, after insert/update query is executed, I have reloaded the page to get fresh data. The page takes 2-3 min to load and then it again starts running normally and there is no load. This happens at any time but not everytime. I kept a watch on Activity Monitor, the Processes peaks are high. It show recent expensive query, but that query hardly takes 1 second to run because every time it will have max 120 rows output. I have added all missing indexes, but no success since my query is already optimized. What could be the cause?

How to fix major lag in NSTimers?

In a fairly simple application that I am making, I use many NSTimers, one which runs at a rate of .01 seconds that I use to change the position of multiple images. This causes major lag. How can I fix this? Please explain in detail, as I am fairly new to app dev.
From the NSTimer Docs (emphasis: mine):
A timer is not a real-time mechanism; it fires only when one of the
run loop modes to which the timer has been added is running and able
to check if the timer’s firing time has passed. Because of the various
input sources a typical run loop manages, the effective resolution of
the time interval for a timer is limited to on the order of 50-100
milliseconds. If a timer’s firing time occurs during a long callout or
while the run loop is in a mode that is not monitoring the timer, the
timer does not fire until the next time the run loop checks the timer.
Therefore, the actual time at which the timer fires potentially can be
a significant period of time after the scheduled firing time.
If you want to work at the display frequency, see CADisplayLink.
However, you should first understand where you program spends its time now to understand what makes it slow (profiler).

timing a method's duration

I have a splash that displays at my app's startup while it loads data from a Web query. I'd like to make sure the splash displays for at least 3 seconds, but sometimes the load query takes less than this. However, I don't want this 3 seconds added to the time it takes to load the web data; I just want to make sure the minimum is 3 seconds.
In other words, can I time how long it takes to load the data, then maybe set a delay for the difference between that load time and 3 seconds, and make the splash hang on (using a selctor or something) for that extra amount of time?
I'd suggest that instead of doing it that way, you start a 3 second long timer when you start the load query. When each finishes, set a boolean to say that one finished and call a method that checks if both are done yet; if so, it's time to close the splash window. (sorry, no code examples - I'm not familiar with Objective C)