Friday, April 8, 2011

Why is my web application seeing latency?

We have an ASP.Net app, that behaves strangely under IIS6. The app itself is straightforward ASP.Net 2.0 Webforms deal, nothing too weird is going on in there (there are couple HTTP Modules in the pipeline, but I wouldn't consider those weird :) ). The thing I don't understand is the page execution times, or, more specifically, the difference between the time reported by ASP.Net tracing (trace.axd) and observed by the client (Fiddler). When the app is run on developer's box (WinXP, IIS5.1), the times reported by ASP.Net and Fiddler are very close:

Page exec time             :  0.0919834
Fiddler Total Sequence time:  0.1560980 

I can understand 60ms being spent getting 5KB worth of data from IIS to Fiddler (both of which run on the same machine, BTW). Now, when we move the code to the server (Win2k3, IIS6), the picture changes dramatically:

Page exec time             :  0.1702014
Fiddler Total Sequence time:  0.5156283 

This is same page, and Fiddler is again running on the same machine with the code. Why does it suddenly take 350ms to deliver the same 5KB?

PS. On both machines the results are obtained by accessing the URL via the actual machine's hostname, e.g. http://machinename/app/page.aspx (as opposed to http://localhost/app/page.aspx).

PPS. Configuration-wise, the setups of a dev box and the server are as close as we could make them -- both use the exact same web.config. Both hit the DB (sql server) with integrated auth, and, consequently, the app runs under a domain account. The app uses forms authentication, and does NOT impersonate (i.e. it always runs under the same account). Now, the way this works on IIS5 is different from IIS6 -- on IIS5 the account is specified in tag in the machine.config, and on IIS6 it's the AppPool setting. The setup seems pretty typical for both environments, and I can't imagine it causing 350ms delays...

From stackoverflow
  • Do a trace route on the URL you are calling and compare them. I am betting with the developer machine you are staying internal to the machine, but on the production machine you are going external and then coming back in through the IP Address.

    If this is the case try adding this to your hosts file (c:\windows\system32\drivers\etc\hosts

    www.mysite.com    127.0.0.1
    

    This will make sure your request doesn't venture outside of the machine to make the request. You should see the response times to start to come in line with each other.

    Update

    Given the new updates. If the server is under load, while testing on production this could account for the difference, because it is actively trying to deliver more requests than the development machine which is only trying to deliver 1.

    Or it could be because you are testing two different version of IIS, 5.1 on XP and 6.0 on 2003. Really can't account for the differences unless the two environments are running the same software.

    : Nope. We are using IE7 to drive Fiddler in both cases, and since IE7 bypasses proxies on requests to localhost, we have to use the actual hostname in both cases.
    : BTW, what do you mean by "venture outside"? The only "venturing" I can think of is a DNS request, and it's all cached long before the time of the test...
    Nick Berardi : so you are actually calling http://localhost on your webserver and dev machine and getting these response differences? Because that changes you whole question and probably should have been mentioned.
    : We are calling http://machinename in both cases. However, even if it was http://localhost, I don't see how does it make a shred of a difference either way.
    Nick Berardi : Well it makes a difference if you are testing localhost vs your URL. That was my question to you. Since your are doing both by localhost, are you doing them while the server is processing real requests?
    : No, the server is idle. It's a dedicated "perf" box, that does nothing but run performance tests (we actually like to know how does the app perform before we push it into production).
    Nick Berardi : makes sense. just wasn't in the question so I had to ask. Have you tried setting up Windows 2003 on the developer machine to see how that performs. So that you are using the same version of IIS.
    : What's puzzling is not the raw performance per se, but the large difference between the times reported by ASP.Net and observed by Fiddler on W2k3.
  • Is the app running in identical release configurations on both boxes?

    EDIT: The Request pipeline changed enormously between IIS5 and IIS6, trace.axd is only going to see the ASP.NET portion of it, not the new app pool and HTTP.Sys components.

    I'd imagine that configuration can be adjusted on IIS6 a bit, but you are probably looking at the difference of a lightweight non production webserver (IIS5) and a robust webserver with individual application pools to manage and more layers of abstraction.

    : Added PPS to the question. Basically, the setups are "as close as we could make them"
    : If this were the case, then EVERY .aspx page would take at least 350ms to come back. Which is obviously not the case.
  • After expending one of the precious few support incidents we've got with our MSDN subscription, I finally know the correct answer to "where is all this time spent" question. In short, the time is spent in HTTP modules we have in our pipeline. The time measurements reported by ASP.Net trace.axd record only the time spent in the .aspx page itself, modules are NOT included.

    One easy way to ascertain this (and see how long does every module take to do its thing) is to use the ETW (Event Tracing for Windows). Here is the explanation (I strongly suspect that this post was written after they looked at our case :)) One thing I can add to the excellent description above is that I used the SvcTraceViewer instead of LogParser to analyze the trace output.

    Update: the above approach also works on Windows Server 2008, just make sure that you have Tracing installed.

MSSQL Server Management Studio (SSMS) 2005 New Query Template

How do I change a default "New Query" template in SSMS 2005?

From stackoverflow
  • Posted this question as a reference, I did some googling, and found a simple way of doing it.

    All you need to do is to edit SQLFile.sql located here: <%= your SQL install dir %>\90\Tools\Binn\VSShell\Common7\IDE\SqlWorkbenchProjectItems\SQL\SQLFile.sql

    Also, Ctrl+Alt+T will show you all the other templates in SSMS; and check out Free SQL Server tools while you're at it.

    stack : You da man, thanks for putting this here!
  • SUPER!!! Vielen Dank!

    Viele Grüße Lars

    roman m : you should make this a comment rather than an answer

Java AWT - BufferedImage problems when using J2ME and J9

Hey,

I'm trying to use the BufferedImage class in AWT. I'm using J2ME on IBM's J9 virtual machine.

When I try and call the BufferedImge.getRastor() method I get the following exception:

Exception in thread "main" java.lang.NoSuchMethodError: java/awt/image/BufferedImage.getRastor()Ljava/awt/image/WritableRaster;

Now, from what I know about the JVM that error is basically telling me that the BufferedImage class does not have a method called getRastor() which returns a WritableRaster object, however this method is documented in the API and it's from version 1.4.2 so should be compatable with J2ME.

I have no idea what is going on here, can you help?

Cheers,

Pete

From stackoverflow
  • I don't think this is your answer... but since you quoted your exception and I assume you cut and pasted it, I'll try to help.

    Isn't the method:

    getRaster
    

    not

    getRastor
    

    ?

    (sorry if this is not what it is ailing you...)

  • You won't be able to use anything from AWT in J2ME since its not supported.

    That happens because J2ME doesn't have AWT. AWT is intended to be used in desktop applications (Java SE), with a different user model and functionalities.

    You can take a look at J2ME docs here

    J2ME uses a different approach regarding GUIs, you may use the high level abstraction API (FORMS) and the low level API (CANVAS).

    Decio Lira : Maybe because your IDE has JavaSE on the classpath. I'm not sure.:/ What are you using? the sun's Wireless toolkit? Or some proprietary toolkit? Can you sucefully run this code on the actual device?
  • The accepted answer is not correct (as of 2009-08-05). Exactly which API's you have available depends on the configuration and profile combination you deploy. However, you do need to refer to the J2ME documentation for exactly which 1.4 classes and members are supported.

    Using CDC 1.0 with Personal Profile 1.1 you get a cut-down version of Java SE 1.4. Personal Profile 1.0 is a cut-down Java SE 1.3. Both have a fairly complete implementation of AWT (no Swing, though).

    We actually use J9's CDC/PP on handheld/PDA devices quite successfully.

javascript for new tab (CTRL+T), new window (CTRL+N)?

When flash has keyboard focus, CTRL+T (new tab) and CTRL+N (new window) are intercepted by flash.

Is there a way to pass these events through to the browser so that they work (opening new tab, opening new browser) OR is there a javascript command for these actions?

From stackoverflow
  • Closest you could get is to have ActionScript trigger Javascript to open a blank window to a blank URL

    // We abstract it in a function here in case we want to
    // change it later
    function openBlankWindow()
    {
       window.open( '' );
    }
    

    For most people, this will launch a new window or a new tab (depending on their browser preferences) but since it is being initiated by the web page, may be subject to pop-up blockers.

    There is no way to actually ask the browser to specifically do one of the two tasks you are asking about. I would be a security/annoyance nightmare if web pages had the permissions/privileges to do that.

    Daniel Lew : I don't think he wants to give Flash access to the browser so much as he wants normal browser functionality to work even inside of Flash.
    Peter Bailey : I know that, which is why the very first thing I said was "closest you could get". Allowing key-commands to bubble-up out of a flash movie to the browser is something only Adobe could fix.
    Daniel Lew : I was responding to your last paragraph, not the rest - the rest makes sense to me.
  • This is a long standing issue with Flash and browsers. (And I mean long - check out this eight-year-old bug on Mozilla browsers.) The problem is that Flash intercepts all input events, rather than the browser. It's sandboxed in its own environment, and doesn't pass events back to the browser.

    Conceptually, this isn't necessarily a bad thing. What happens when Flash wants to listen to a "ctrl + n" event? Should the browser take focus away from Flash because it uses that hotkey already? It'd be a real pain for Flash developers, that is for sure.

    There have been proposals on how to fix this issue that I've seen for particular browsers, but there's no catch-all solution. For example, this solution is referenced in the bug, but it obviously won't work the way you want (since the user will have to jump through quite a few hoops to get it working).

    So... no, for now. Would be really neat if this problem could be fixed.

    Ben Blank : "Should the browser take focus away from Flash because it uses that hotkey already?" — Yes! Flash is a "guest" in the browser's "house". And a particularly ill-behaved one, too. :-)
    Daniel Lew : Hahaha, I've never heard the guest analogy before for plugins, that's pretty awesome.
  • Peter Bailey is pretty much right on. But he didn't give much of example.

    Hopefully the example below will help people incorporate such functionality in our apps. Probably with a little work we could write a class to replicate most of the browser functionality. At least all that can be replicated via JavaScript. And just include it in our apps.

    http://thesaj.wordpress.com/2009/12/05/how-to-enable-cntrl-t-tab-in-flash/

Is there a way to set a asp.net button's CommandArgument in javascript?

I have a GridView that lists a bunch of items and one of the columns has a link that displays a modal (AjaxToolkit ModalPopupExtender). Let's call that link "Show". In that modal, I have a asp:button for saving the data entered in that modal. Let's call that button "Save"

So when the user clicks on a "Show" link in a certain row, I'd like write some javascript that sets something in the "Save" button, so that in my code-behind, I can handle "Save".Command and use the CommandEventArgs parameter to get the value.

Is this possible, or do I just need to use a hidden input tag and set its value?

From stackoverflow
  • Not a direct answer to your question, but another possible way of solving the problem:

    Place a HiddenField control on the page. In your code-behind, before displaying the modal popup, set the value of that control to the ID of the row that was clicked (or the row number, or some identifying value). Then in the code-behind of your Save button, you can just read the value of the HiddenField.

    slolife : Thanks Brant. Looks like that is the workaround.
  • Well, after continuing the research, it looks like it cannot be done. The CommandArgument property might reside in the ViewState, but for this case, it is completely server side and cannot be changed using javascript.

Overriding int on a bit enum

I saw some .NET 2.0 code which looked like this:

 public enum abc : int
 {
  value1 = 1,
  value2 = 2,
  value3 = 4
 }

etc...

Now I know the flags enum can be used for bit values (like above, right?) so you can do | "or" &, etc, but what is the reason for not using that? What is the point in overriding int?

If I design an enum for choosing multiple values I would use the flags attribute and not override anything (what I don't understand). What does the above approach net?

Thanks

From stackoverflow
  • The ": int" is specifying what to use as the underlying type for enum values; any integral type other than char can be used here. The default is int, so it is redundant in this case.

  • It's not "overriding" int, it's indicating what type the enumeration is based on. The default is int so this actually isn't achieving anything, but in some cases you might want to base an enum on long to store more flags, or byte to save space if there will be very many instances of the enum around and it only has a few values, however the recommendation in the framework design guidelines is to use int unless you have a very good reason not to.

    If this is intended to be a flags enumeration then it should be marked with [Flags], and this appears to be the intention here, so the omission looks like a mistake. You can still combine the values using the bitwise operators even if it isn't marked with [Flags], but from memory I think you get a compiler warning (or it might be an FxCop warning, or possibly a ReSharper warning...).

  • I don't see any benefit. Probably lack of experience on the programmer's part.

  • FlagsAttribute only tells the user that fields in this enum can be combined; it doesn't actually set the fields of the enum to "flaggable" values. This, you will have to do yourself, just like you have already.

  • If you are asking the scenario for choosing specific values, I don't know a good example offhand, but I can imagine something like

    enum Color = {
      Red = 0xFF0000,
      Green = 0x00FF00,
      Blue = 0x0000FF }
    

    maybe being useful.

  • Setting the values on a non-Flags enum to use a 1-hot encoding just for the sake of using a 1-hot encoding doesn't really make any sense. I guess it might make sense if you thought you might make it a Flags enum in the future. Otherwise, the values should either be not overridden or assigned a value based on their meaning (eg. Color.Red = 0xFF0000).

  • In reference to the ": int" specifying the underlying type, if I saw that, I'd have a look around and see if they delcare all their enums that way. If so, they probably just learnt to write enums that way ( or maybe they are a hyper-explicit coder). If however, just this enum was declared this way, perhaps the programmer is trying to say something (that might have been better said with a comment) that it is critical that this has an underlying "int" type. Perhaps it is being binary serialised or deserialised somewhere.

    As for the [Flags] attribute, as far as C# is concerned, you can use bitwise operators on any enum, not just those declared with [Flags]. From your above example, without any [Flags], the following is totally legal:

    abc myAbcValue = value1 | value2;

    The primary difference with respect to the [Flags] is in the ToString() and Parse() methods of Enum. Without [Flags], myAbvValue.ToString() will return "3", but with [Flags] it will return "value1, value2". Likewise, with the [Flags],

    abc yourAbcValue = (abc)Enum.Parse( typeof(abc), "value1, value2") ;

    will set the underlying value of yourAbcValue to 3.

    Note that the IsDefined() method of Enum() does not allow for multiple values with [Flags] enums, so:

    Enum.IsDefined( typeof(abc), "value1, value2")

    returns false regardless of the use of [Flags].

    Also note that [Flags] provides information for any reflection access, and other languages may treat the restriction on flagged enums differntly to normal enums.

How to make a structure map powered viewengine in asp.net mvc

My views extend a base view class ive made:

public class BaseView : ViewPage

At the moment im calling ObjectFactory.GetInstance inside this class' constructor to get some interface implementations but id like to use structuremap to inject them as constructor arguments.

Im using a structuremapcontrollerfactory to create my controllers, but how can i do the same for views?

I know i can implement a custom ViewEngine, but using reflector to look at the mvc default viewengine and its dependencies, it seems to go on and on and i'd rather not have to re-implement stuff thats already there. Has anyone got a cunning idea how to solve this?

I know i could make things easier with setter instead of constructor injection but id rather avoid that if possible.

From stackoverflow
  • Yes, if you are talking about the WebForms ViewEngine, you are correct in your assessment that it was not designed with inversion of control in mind. You can either lobby Microsoft to change it, or you can use setter injection. In FubuMVC, we use setter injection along with StructureMap's BuildUp method:

    Andrew Bullock : setter injection it is