Friday, 6 July 2012

Learning HTML5

For a diversion, and for my own edification, I'm learning HTML 5.  I used to have a very academic understanding of HTML (4 and 4.01) and was very familiar with DFDs and the spec.  It's been a long time since then, and I need to learn CSS and javascript as well as the new HTML5 capabilities.

For starters I'm using material available on w3schools.com which I've found in the past to be a good teaching website - if again slightly academic in its slant.

Whither do you put javascript?

That's the first big thing I'm finding.
The sample on HTML5 drag and drop puts the javascript in the document's head section - and it works fine.  But the sample on HTML5 video DOM puts the javascript in the document's body - and it wont work if the javascript is in the header.   Why is that?

Monday, 14 May 2012

Outstanding Issues

A wash list of the Outstanding Issues I'm hoping to address.  This may grow as more bugs are uncovered or as I partially fix things.

  1. Intermittent timeouts in production when users try to zip up and download multiple files.
  2. Errors when uploading a file and assigning multiple entities to the new file. [fixed].
  3. The app is slow, especially for the first page load.
  4. Calls from the ASP.Net presentation tier to the WCF app tier do not work correctly in a load balanced environment.  Calls must only be routed to http://localhost.  This appears to be a consequence of impersonating another ID when running the app. 
  5. The app impersonates another ID.
  6. As yet, I can't actually get the WCF services to run locally on my dev machine.
  7. There is no logging on tracing. [fixed]

Bug fix: associating entities with a newly uploaded file

This bug had nothing to do with the actual file upload, or, to be honest, the developers.  In a recent (i.e. since the application was developed and handed over to us) security update Microsoft put a pretty low limit on the number max number of keys in a http collection and the app is blowing that maximum.

The fix is pretty simple when you know how.  Add this key into the web.config's <appSettings>.  I chose the value of 15,000 to give myself plenty of room.
<add key="aspnet:MaxHttpCollectionKeys" value="15000" />

The downside of this large collection is the huge amount of data being returned to the user's web browser (>1Mb) as previously mentioned. It's causing the app to appear to be incredibly slow when in fact its the data transfer and rendering of the page that cause the sluggish UI.


This fixes Outstanding Issue 2

Logging and tracing

There is no logging or tracing in the application so trouble shooting is near impossible, particularly for the timeout issue which was the first issue uncovered.

Enabling logging on the ASP.Net Presentation Tier
I added the following to the web.config to enable tracing in the web tier.  Initially I was logging "verbose" but as it was too much info I turned the volume down to "information".

Add this into the existing <system.serviceModel> section.

<diagnostics>
  <messageLogging
       logEntireMessage="true"
       logMalformedMessages="true"
       logMessagesAtServiceLevel="true"
       logMessagesAtTransportLevel="true"
       maxMessagesToLog="3000"
   />
</
diagnostics>


Add the new <system.diagnostics> section before the closing </configuration> tag.

<system.diagnostics>
 <trace autoflush="true" />
   <sources>
      <source name="System.ServiceModel" switchValue="Info">
          <listeners>
              <add name="xml"/>
        </listeners>
     </source>
     <source name="System.ServiceModel.MessageLogging">
       <listeners>
           <add name="xml"/>
       </listeners>
      </source>
   </sources>
  <sharedListeners>
      <add name="xml"
               type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="D:\inetpub\MyApp\Trace.svclog"

      />
   </sharedListeners>
</system.diagnostics>

The hard part is then getting the log file off the server as I don't have access to it.  But it does give some useful information in that I can see the full SOAP request and response between the web and app tiers.  Tracing will be easier to get my hands on.

Enabling tracing of the web tier
The web tier can be easily enabled for tracing, thus letting me see specific methods being called and timing information for how long  they execute.  I output the tracing to the separate trace.axd file in the app's home directory.
<trace enabled="true" pageOutput="false" requestLimit="40" traceMode="SortByTime" localOnly="false"/>
With that in place I can now add trace statements into the methods thus:-

if (Trace.IsEnabled)
{
Trace.Write("Entered Page_Load");
}
or even
if (Trace.IsEnabled)
{
Trace.Write("gvRow is completed: " + i);
}

These have revealed some interesting things that I must still address:-
1. The page contains a grid with >1,000 rows so when rendering the resultant page there is >1MB being returned to the user's web browser.  No wonder it is slow!

2. If the message size returned from the WCF service to the consuming web tier >512Kb (I think) then it takes approx 45seconds to deliver to the Transport layer.  There is then a further 45 seconds to pass it from the Transport layer up to the Messaging layer within the presentation tier!
I also believe that a reason for the slow speed is that the site impersonates another user.  This is also causing problems in a load balanced environment where the app doesn't seem to be able to call out to the load balancer when calling the WCF services.  It can only route the request to http://localhost/MyWCFservices/ServiceEndpoint.svc.

 

Setting the scene: Getting to grips with an inherited app

I seem to be the primary support in my work for an internal app developed by contractors for us.  They were able to produce the app without the usual restrictions, styles and frameworks imposed on internal staff by my company.  As a result the architecture and approach is modern and unlike anything I come across in work.  It's a fantastic opportunity to learn about modern coding styles and techniques!

The application is an ASP.Net 3.5 web app with WCF services as the app tier and a database plus NAS share for the data tier.  It's written using C# in a CQRS pattern.

But there are problems with the application:-

1. Intermittent timeouts in production when users try to zip up and download multiple files.
2. Errors when uploading a file and assigning multiple entities to the new file.
3. The app is slow, especially for the first page load.
4. Calls from the ASP.Net presentation tier to the WCF app tier do not work correctly in a load balanced environment.  Calls must only be routed to http://localhost.  This appears to be a consequence of impersonating another ID when running the app.  The authentication is lost if we route via the load balancer in a double hop.
This blog will capture my learnings and fixes applied.