Effecient Coding for low end CPU - c#

I have a application built in Silverlight, which will run on a ATOM processor (was told around 1.6GHZ).
So far tested another application with lesser functions on another Mini PC and it can still run smoothly.
This application will be user interactive, and will have 4-5 different pages to be displayed.
So to navigate from page to page, I currently have 2 options, but not sure which is a better way considering the low end CPU. (pages are static, nothing generated on the fly)
1)Load the 4 - 5 pages during the onLoad event, shown the 1st page using Visibility.Visible.
The other pages will be Visibility.Collasped. This way, only need to toggle the Visibility property, pages need not be destroyed and re-created.
2)Initialize all the pages when loaded. Use Container.child to attach the wanted page. Not sure about the capability about this, but for other applications, I usually choose this method.
*P/S: I am okay if it takes a while to load,as the application will be loaded only once per day. As long as during the running period, it does not lag(using touchscreen) I am more than happy.

The main trick is to keep effects to a minimum. Animations etc. - not a problem in a normal application, more in a game or something. For normal LOB style apps, the CPU would not be too busy anyway.

Related

UWP App performance degradation after usage - Windows 10

I am using MVVM-Caliburn in my UWP application. There is a page where the user can add contacts on a form, and even increase the number of forms by clicking a button (the form is presented in a ListView, with multiple entries as per usage).
I have turned page caching as ENABLED.
this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
The problem is that after a while, this particular page starts to slow down a lot and certain operations (even textbox input!) starts to take a lot of time.
Does this have to do with the fact that something gets cached and after a while, it starts to affect down the application performance?
Any help or direction in this matter will be welcomed.

Bing maps control hangs the back navigation

I recently ran into weird bug in Bing map control. In short, if the connection is poor and you press the hardware back button on page with map while the map is still loading some tiles, the navigation process hangs up (some times up to 10 or even more seconds). And in case when the time is more than 3 seconds the app will be "a little" not user-friendly and will not meet the technical certification requirements (5.1.3).
To repeat the bug you can create the app with two pages. First one with button to navigate to the second page. And the second page with just map control with high ZoomLevel (more than 14 for example). After the app launches, you navigate to the second page and move map to some unloaded area and then (without waiting for the download to complete) press the hardware back button. And also you somehow must "create poor" connection (in my case, simply disconnecting the device from the computer is enough).
And does anyone have any idea why this occurs and how to workaround it?
EDIT: The same bug can be observed in the Foursquare application for wp7 - if you go to the page where the place is shown on the map in full screen, then slide the map into an unloaded region and press the hardware button back.
It seems that the problem is in the Bing Map Control.
Hide the Maps control using the Visibility first, before you navigate out of the page. That way the control will become inactive and memory consumption of the page will decrease, thus allowing to switch pages faster.

asp timer and update panel

I have a small web application I am working on that is basically a radio player that plays live radio. On the player we have the schedule and what's playing now etc. I used a asp timer and update panel to update various content on the player mainly the 'what's playing now' bit.
Last time we tried to use the asp timer and update panel on our website it crashed the webserver in minutes because the cpu went to 100% and it could not handle that many postbacks. I am wondering what the best way of optimizing this radio player is so that it does not crash?
I have thought I could load all the content in on page load in hidden fields then use jquery? Sounds a bit messy but open to ideas?
Creating some Javascript that updates the update panel on certain timestamps isn't that much work. Send the expected end-time to the browser and let it update once the song ends.
You can even send a list of queued songs to the browser so it only has to update the data once in a while. (depending on play list style)
Make sure the update panel server side uses as much as possible cached output so it does not have to find the currently playing song. IIRC an update panel has quite some overhead, calling a clean JSON request to only retrieve the currently playing song might be much cleaner.
check view state is not enabled - this will quickly eat up memory.
You could use JQuery to fill in a portion of your page (or several portions) after the initial PageLoad. I have learnt how to do this recently and it feels better than the timer and update panels. See this post for how I achieved it - the answer from jwiscarson has the detail.

Why does my new .Net 4.0 EF application randomly lock up?

I have recently rolled out a new ASP .Net application. This application uses .Net 4.0 and the Entity Framework 4. It is a "basic" CRUD application. I almost exclusively used the EntityDataSource for Data Access.
The users have reported "ocassional freezing" of the application (they all use IE 8). If the user closes his browser and starts back up, the app is fine. It happens maybe once or twice per day total, usually to the heavy users. (So, I have been leaning toward memory leack or some other kind of resource limitation.)
Until just a little while ago, I have never seen this happen. It dosn't leave anything in the Event Log on the client PC nor Server. Also, there is nothing in the IIS error logs or the SQL logs.
A little while ago, I finally got it to happen. I was switching all of my EntityDataSources to use a single Object Context per page. I downloaded the EF Profiler (which seems to be a great product) and it pointed out that I am using multiple object contexts on many of my pages, due to the fact that many of them have more than one EntityDataSource. So, I was cleaning all this up and testing each page, when lo and behold....IE stopped loading pages!
At first, the page started loading slowly (and this was a page that I had already modified to use a single Object Context, so although I still believe I need to implement this "singleton" pattern throughout all my pages, I guess it isn't the culprit! Anyway..), then at some point I received:
Message: Sys.WebForms.PageRequestManagerTimeoutException: The server request timed out.
Still, nothing in the Event Log. I also checked the IIS web logs and I don't see anything, but they are pretty tough to read with the naked eye, I may have to download a parser to make sure there is nothing in there.
Anyway, I decided to start up another window and navigate to my app, and sure enough that window worked fine, no problems. I went back to the windows that stopped responding, refreshed it, waited... went to the home page of my app (which is basically just some static html.. and nothing.. ). Next, I opened a new tab in the window that is currently frozen and that tab works fine. So, I go back to the window that can no longer load pages from my app and try some other web sites.... espn.com loads fine, msn.com loads fine, I then enter the URL for my app home page (and tried some other pages in my app) and NOTHING. IIS doesn't even log the attempts in its Log Files (its like IE has just decided not to do anymore "gets" for my localhost!). Finally, after waiting for a while (while I was typing this post) I now have this error message in that window:
Internet Explorer cannot display the webpage. What you can try: The problem can be caused by a variety of issues, including: BLAH BLAH BLAH...
So, I jump back to that window and it can still browse Internet sites just fine. But, once again when I try to go to any of the pages in my app, I get NOTHING (spinning blue circle in the tab). So, once again I start a new tab in that same browser and I can browse around my application just fine.
What has my app done to this browser instance that will no longer let it load any of its pages (in fact, it seems like it isn't even doing a GET on any of the apps pages, since there is nothing new in the IIS logs...except for when I load the pages in these other tabs and/or browser windows that work fine, so the logging is still working...)? I will be forever indebted to the person that can help me figure this out. I am not sure it will do much good, but I am going to leave this browser window up on the chance that someone can tell me some things to try to diagnose this problem. It feel like I am THIS close to figuring it out. I finally have a window up that is misbehaving. I am afraid to close the window or do a new build on the app until I get some good input on things to try....
I should add that when this happened to me, I was running on my local PC, so I was the only user and only had one window open to the app..
Although, I am completely stumped!
We had the same issue and seemed to fix it by adding the following JavaScript to all pages with ajax:
window.onunload = abortRequest;
function abortRequest() {
Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
}
I hope this helps!
sounds like a request just takes too long to execute. A web-browser is only allowed to keep two concurrent connections to a single webserver unless you utilize http pipelining (which isn't well supported anyway). However, My experience is that this is per browser, not per tab.
This is why nothing shows up in your logs, because your browser never initiate a request because it is waiting for the page to finish loading before it can fetch another page. I would start looking into the last request initiated before the lockup, it is probably that page that locks for some reason and never finishes.
ASP.NET utilizes only one thread as long as all request are sequential. As soon as you fire up two request simultaneously, a new thread is initiated (Init() on HttpApplication is invoked), and that can cause intermittent errors if you do funky stuff on Init().
If you think this is related to EF, you might read up on how to avoid locking in multi-threaded environment (because a web application is very much multi-threaded however this usually kicks in a production environment).
Ugh, I feel your pain - I hate these types of issues. Here's my divide-n-conquer process when something like this is happening (adapted somewhat to your case):
Step 1 - Environment Visibility
Get yourself set up so you can roughly see inside your systems. Set up Performance Monitor, and add a couple of important counters (IIS Current Requests, ASP.NET Current Requests, SQL Server - Active Transactions). The idea here with the "active requests/transactions" counters is you want to find out which part of the system is holding on to the request.
Additionally, add counters for total request time in IIS and the DB (so you can see it climbing as something is hanging on).
On your client PC, set up Fiddler.
Step 2 - Reproduce Issue
Usually at this point, the application realizes you can see it and starts behaving perfectly. ;) Stop and make sure you can still reproduce the issue.
Step 3 - Take the DB out of the equation
Create 4 pages in your application:
Static HTML file (.htm) that will NOT go through the ASP.NET runtime engine. This is your baseline for raw IIS.
ASPX page with no tricks (no database access, no processing, just a simple page that ASP.NET can spit out)
ASPX page with one simple database call (of some size, maybe do a single big query or something)
ASPX page with some complex transactions (multiple queries, etc)
Step 4 - Reproduce and measure
Since this issue will probably be pretty obvious once you can see it, find the bottleneck with your performance counters and Fiddler. Your issue sounds like you could have an intermittent connectivity issue (either between client and web server or web server/SQL), especially if IE is giving you the "page cannot be displayed" error, but you should see that in Fiddler. On the server side, you should see one of those performance counters hanging.
well, sounds like the app is waiting for a database operation to complete but is locked, probably because of another operation.
Try using the SQL profiler to trace the activity, and isolate what processes are running for a long time.
You can differentiate the requests using the SPID column in the trace view, it contains a unique ID number for each session from your App.
I have new information regarding this issue.
The application uses Integrated Authentication. This causes every reqest to come back (twice) with access denied, before IE send the credentials.
I can't help but wonder if this is what could be causing the "time outs".
I implemented an Ajax "Loading" animation on every page that prevents the user from clicking a button until the previous request is completed and that has GREATLY diminished the amount of "freezes" the users are experiencing.
Although, it still happens somewhat often.

Slow Performance -- ASP .NET ASPNET_WP.EXE and CSC.EXE Running After Clicking Redirect Link

I click on a link from one page that does a redirect to another page (Response.Redirect(page.aspx)).
The browser churns for about 30 seconds and the page displays. I'm trying to track down why it takes so long to load the page.
The page hosts two other custom controls.
I have commented out the lines of code for each and both controls, and the page still takes about 30 seconds to load.
I've set breakpoints on the Page_Load event for each of the controls as well as page.aspx and it also takes about 30 seconds from clicking the link with the Response.Redirect to the first break point.
I loaded up task manager and clicked on the link. I notice aspnet_wp.exe and csc.exe run during this 30 second time frame.
I'm wondering if there are some sort of code-behind shinanigans going on while I'm waiting for the page to load.
This only occurs the first time I click on the link. Afterwards, it's not as slow.
I've googled but there's not a lot of useful information about this. Anyone have any ideas?
Thanks,
---Dan---
The very first time that the page is load, then the asp.net compile a lot of pages, almost every one found on the same dir, including modules, and dlls found on bin.
To speed up (your development) try use this option on web.config (only on your development computer).
<compilation batch="false" ... >
Using batch="false" asp.net compiles only one page, the one you are on it, so you get a big time the first time for the dlls, but after that, is a lot less if you have 200 pages, and you only change one, and you develop/debug only one.
Also if you can, try do not use App_Code directory, and place all your code inside a dll.
Look more about compilation options on web.config to make it even run faster, change for example the temporary directory to a faster different disk than the C:.
Second trick
I will like to say one more trick that I found here on stackoverflow.
<compilation optimizeCompilations="true">
You only need to have install an ms patch http://support.microsoft.com/kb/961884
I have test it and the results are very good.
.net 4 and Visual studio 2010
The same think stands, but you do not need to run the patch.
Web Farm
I have notice that on web farm the first time that application is run, if you have many work on global.asax on application start, then I recoment to use Mutex and let only one pool make the compile of the pages ! Or else there are possibilities for conflicts and huge delay to start the application - especial if you use mutex on other part of the program.
The fact that csc.exe is running and it only occurs when you first click the link would suggest there are a lot of elements in the aspx that need to be compiled prior to displaying the page. Look for stuff that exists in expression holes <%= %>. It could also be something in the controls themselves (particularly if they are ascx user controls and not server controls).
The reason it only happens the first time you click on the link is because after that the compiled page object is cached, so there is no need to re-compile until your app is restarted.

Categories