Are there any issues with changing elements which will appear on a web page within a thread. I am from a windows programming background and obviously if a thread needs to change the GUI in some way you have to delegate it to the GUI thread.
Basically my page uses 3 sql queries which can be run concurrently to obtain the page data. So I setup 3 threads and have them run, if one fails or has no records it makes an error message visible about it, this is currently done within the thread and seems to work.
Note: The 3 sql queries are for very different data it is definitely fastest to run 3 separate queries and running them at the same time makes it even faster (In terms of how long it takes the page to display).
Edit: The threads are joined in the page load event
You're going to have to join all 3 threads before rendering the page. Once it's rendered out, there's no updating it.
Basically asp.net rendering is about building a large string, which will be the rendered output, which is a html page. (Not counting dynamic image rendering and such.)
So the short answer is no, above any "normal" threading issues.
Related
At the moment we have a solution which is Web forms ASP.Net 4.0. We do a number of things such as using web methods and services either calling them using the standard web forms way or sometimes to reduce the footprint directly calling them with jQuery ajax posts and gets.
We are looking to improve the way we work but we have heavy constricts regarding how the solution is at the moment and not being able to completely rewrite it.
Updating the page using Ajaxs for data, forms and for example pulling "the next 20" items and displaying them on the page it what I would like to heavily stream line.
Using template's due as PURE and jQuery Templates is fantastic way to produce fast calls back and forth between the servers but results in having two copies of the html. (the template for the jQuery and the code in the actual first render of the page)
We have thought about possible producing a empty template and then always populating it via json data we post down to the server but I feel this isn't how things should be done...
can anyone reckoned the best way we can do this without having two copies of our 'template' (e.g. a row of a table)
You mean you have a template in asp and the same template in javascript, but you'd rather just have 1 or the other?
I think that is really subjective. It is always different based on use case. That being said I'd do it by modifying my views and templates. My views (non-js) would simply have containers for that dynamic content. In other words I'd never load the dynamic portions of content into the views initially. Rather, on page load I would simply load up the template and the json that fills it in.
If you think about it that's 2 more requests, but it makes your life easier. The user also is able to see something on the page sooner.
This is one of those questions that really depends on what you are doing. There are trade-offs to be analyzed with every solution.
We are designing a data capture process with many questions (using ASP.NET), which can repeat (e.g. enter all your vehicles). In rare cases this could be over 100 repeating groups.
Therefore I've stated that rather than having one huge form that we split the application into multiple forms, using logical points for page splits (e.g. personal details) in a wizard style.
However, there is debate within the team as to whether we should be using AJAX/Javascript to have a single form. Suggested approaches to this appear to be:
Load in all the steps in one go, and just use Javascript to toggle.
Load in step 1 and load the other steps using AJAX.
Submit the form using AJAX and load the next step using AJAX.
Option 1 to me defeats the entire point, as you'd end up loading a massive HTML tree - some of the pages can be large. This would be more acceptable if there was a small number of steps with very few questions on each.
Option 2 to me seems overly complex, plus if the user clicks the next button, can you guarantee the next page has loaded? Also, what happens if input from page 1 is required for page 2?
Option 3 seems doable, but I'd have though the response time of doing the AJAX processing would actually be slower than doing a standard form submit, as there would be more processing involved by the client browser. Also this approach is more complex than a standard form submit.
Do you think my approach is correct (standard form posts)? I've read that typically AJAX is used to enhance the functionality of a page, rather than trying to emulate multiple pages.
The Single Page Interface Manifesto talks about how you can build SPI web sites without losing bookmarking, Back/Forward buttons (history navigation) or SEO.
With regards to performance, this is something you can test. But if you go the AJAX route, you should provide an alternative for those users without Javascript. The extra work required may be enough to push the idea off the board.
To my mind, options 2 & 3 lie at ends of a spectrum. You can use AJAX to submit whatever information is required for the next step. Option 2 submits nothing. Submit the entire form, and you have option 3. You'll probably want something in between.
As for performance, there is some processing to be done (collect form data, data transmission, parsing, splicing the result into the document), but the browser will be doing the same tasks with a traditional form; AJAX just makes parts of the process more visible. Since the data is smaller in size (part of a form rather than a full page), performance shouldn't be much worse and may in fact be better. Also, modern javascript engines are very fast.
In any case, listen to MikeB's advice about degrading gracefully when JS isn't supported, unless this is for an internal app where you can depend on browser make & configuration.
I am puzzled. I looked at the trace of a pagecall that was "slow" to load according to my boss, causing the page to partially load, and then "jump" to the memorized scroll-place on a postback.
I found out eventually, using my trace, that my whole loading, from Begin PreInit to End Render, took 1.94 seconds, 1.5 of which are spent between Begin PreRender and End PreRender.
Any idea on what could cause that? The next biggest loadtime is 0.14 seconds, for End PreRenderComplete.
Could the problem originate from my queries to SQL Server, or a too vast quantity of controls on the page, even though most are "hidden"?
[edit:]It seems that my page load is very long when I show a certain form. My total render size is of 91537 bytes, 44483 of which are dedicated to that specific form. My viewstate seems kindof enormous. Also: Can a 404 to a JS file cause that kind of lag on load?
[update:] So I found the longest-running query, and it seems that even though it DOES seem quite chunky, it has ended running long before the page is even loaded.
As added information: I am using quite a bit of SqlDataSources troughout the controls, to fill my dropdownlists and other interesting stuff of the like. Is that cluttering my app?
In my experience (same problem as you), it's 90% a SQL issue.
Put some Stopwatch(es) around the query you are calling to find out which query is running slow.
Rendering asp.net control can't take so long....
In order to identify the cause of a bottleneck you really ought to profile your code with a tool like ANTS Profiler or something similar.
A profiler will allow you to pinpoint the problem area by showing you which lines of code are slower than others.
I would use YSlow to determine if its from something on the client side or server side. We sometimes add timers to some queries then output the time to execute in an html comment... of course removing them when the testing is complete.
Does the page call anything hosted on an external site?
Your best bet is to use the Perfomance Wizard in Visual Studio and look at the Call Tree for your page. It will give you more details into the exact performance bottleneck.
I have seen this type of performance when there are too many complex controls declared on the page. Although it could easily be SQL related as well. To know for certain you need to look at the Call Tree and find out what the most expensive call is.
Of course, if it is sql-related, as many people have noted, "sql server profiler" is the tool to use (given that you're running mssql). mysql has "jetprofiler" (.com) which i haven't tried. once you've found the slow query, it's not rarely an indexing issue.
I have developed a site using Asp.net C# 3.5 and now I feel that some of the pages are loading reeeaaally slooooow. I now need to start going through the website and try to find out whats making it so slow. But I don't know where to start, whats most likely causing the problem? Where do you usually start when trying to find out what is wrong?
One page that is very slow uses the following:
Asp.net C# 3.5
AjaxControlToolkit (http://www.asp.net/ajax/AjaxControlToolkit/Samples/)
RoundedCornersExtender
CollapsiblePanelExtender
Two different UpdatePanels
11 connections to a MySql database (one quite heavy, using some unions and inner joins)
Most of the connections to the database results in populating FormViews or GridViews, so totally I have 2 formviews and 6 gridviews on the page (every gridview show max 10 items)
Can a CSS-file slow down the site? The CSS file I use is about 60kb.
Can using the AjaxControlToolkit make the site slow? Is there a better way to use javascripts on the site?
I understand that it's impossible for you to help me locate the problem with slow load but where you would start to look for the problem? The DataControllers? The AjaxControlToolkit? The sql? Is it an easy way to find out if a query in mysql is slow? And what is slow? Is 0.3s slow for a large query?
As you see I have many questions, maybe you could just help me start working in the right direction, thanks really much for your help!
You could start adding Trace="True" into your <%# Page %> directive and see where your pages spent most time; also check your web.config and config debug is disabled.
You can also use Performance Monitor to help you to identify your application main bottlenecks
Don't forget about
ASP.NET Tracing
as probably the first, and simplest thing, to start diagnosing ASP.NET problems.
If you want to get a bit more in-depth, don't forget to try:
ASP.NET Health Monitoring
From what you say, though, personally, I'd look into possibly reducing those database connections. Data access is always a major bottleneck (or can be). 11 connections is quite a lot for a single page, especially if one or more of those connection does "heavy" work as you say. Could the page be split into two or more pages? If the problem is in the rendering of the page, the output from ASP.NET Tracing should help in this regard.
The CSS file, whilst quite large at 60kb, is possibly the least likely culprit as most browsers will cache the CSS file after the first request.
My general method when dealing with something like this is always the same. I start removing functionality - javascript/css/include files - until the page becomes more responsive - often i take the page back to minimum complexity and build from here. Adding them back one by one you should be able to identify where your bottleneck is. You can also use tools like (for MySQL) the slow query log to identify problematic queries. Abstracting your queries out and running them in phpmyadmin (or similar) can also help you recognise which queries are problems if this is the case.
I guess the first thing you need to identify is what exactly is "slow" about the page, is it rendering time? load time? identifying this should give you a good starting point.
First of all you will need to do some profiling/measuring to find out which part of the application is slow, e.g:
long running db queries
CPU/memory usage on the web/db server
amount of data transferred between web server and client (browser)
time it takes to render the pages in the browser (javascript)
I'd start with checking how long those SQL queries are taking to execute. Not sure what the SQL Profiler type tool for MySql would be called. If that is not the culprit you could create a TraceAttribute as shown here to see how long each of your methods take to execute. If that is not the culprit you could go onto using something like FireBug or Fiddler to see how long each part of your site takes to load and how long each request takes. You could also use Tracing instead of Post Sharp, but when you have a hammer every problem looks like a nail.
In our application (a game), in some cases it can't run fast enough. Obviously we'd like to speed it up, but in the mean-time when this happens it causes many problems (or if it's not causing them, the two are related).
The one which is least related to our own functionality is that the built in Alert.show() method stops working. Typically the full-screen transparent box appears but not the actual popup. I believe this is down to Flex giving all available cycles to other tasks... but it's proving difficult to investigate analytically so I am happy to hear another explanation.
To clarify, core parts of Flex are simply not working in this situation. I've stepped through the code for instance where a new element is added to the screen, everything happens and the addChild() method is called on the main display canvas... but then the element does not appear. If we then disable our update loop, the element suddenly appears.
So whether Flex is supposed to run the exact same code or not, somehow it IS blocking is some strange way. As I said, even the Flex Alert.show() method doesn't work.
All Flash content is executed frame-by-frame - Flash executes one frame's worth of code, then updates the screen, and then waits until the next frame update.
When Flash can't keep up with the specified framerate, all that happens is that instead of waiting between frame updates, Flash does them as fast as it can with no waiting in between. So the only visible difference is that frame updates occur less frequently. There are never cases where code is skipped, events are dropped, or screen redraws are skipped for performance reasons (unless you've found new bugs).
So the most likely culprit is that either you have a problem with code that's very time-dependent (such as code that expects two timers to trigger on the same frame), or some other problem that's being misdiagnosed. (For example, maybe there's a bug causing a slowdown, rather than a slowdown causing your bug.)
I'm not too sure if Flex has some additional performance handling of it's own. But for pure actionscript the only thing that would happen is the framerate would slow to a crawl, everything will happen normally just slower. If you stack very large amounts of transparent or masked objects you might get some weird behavior, but that should be more noticable.
And I guess telling you that making a game in Flex isn't that much of a good idea (just because of the performance overhead the framework has) is a bit late ;)
I like to make games in FLEX 3 (actionscript3), its actually pretty handy solution when compared to Flash CS3: good debugging environment without hassle.
Of course it depends on the game style which one is better, if you need lot of graphics you may like Flash more, but Flex allows you to use external images, components, etc. Notice I am not talking about Flex XML project here.
Answer to your performance issue: You can use e.g. old MacOSX machine to see what happens in a very slow machine, a few solutions are:
- move objects more than x++ y++ pixels when machine is old
- reduce objects
you can detect with a timer how slow machine is..