Jump to content

Basically I have a .Net app that intercepts an http request, gets the user info via Request.User, gets the user's adgroups, adds them to a request header, and then sends a request to a second server (Java Tomcat) which authorizes API access by those groups. It sends back a result, and then the result is forwarded back to the user through the .Net app.

 

The Java server's response time is only 0.03 seconds even with a database API call. Looping over and comparing the adgroups adds another 0.01 seconds (corporate environment, 200 groups).

 

The .Net app adds 0.3 seconds of overhead somehow even though these two servers are on adjacent boxes in the same room with our DNS agent.

 

Both of these servers run Windows Server 2012, and both are dual socket 8-core E5 V1 Xeons on the same memory configuration and clock speed.

 

The .Net app is using ASP.Net 4.5 on Visual Studio 2010 with code optimization enabled in the project.

 

I do not have the first clue how to troubleshoot and optimize this. If you are interested in helping but want the exact code posted, I may have to get back to you. There's nothing exposing my company, but I think I need approval to post it.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to comment
https://linustechtips.com/topic/670753-fixing-net-performance-problems/
Share on other sites

Link to post
Share on other sites

1 hour ago, Erik Sieghart said:

Have you pinged server to server so you know exact overhead?

Miniscule, 1 millisecond or less.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to post
Share on other sites

Just now, savstars said:

Without the code, this is going to be very hard to help diagnose.  Without it, all I can suggest is to analysis the algorithm you have implemented, and ask yourself, is this the most efficient way of doing this?

I don't see how to make it any leaner than:

 

//I'm not in front of my code so the syntax is gonna be a bit off, but this should be pretty clear and is very close.

 

IndexController ( args ) {

    var wid = User.Identity as WindowsIdentity

    var adgroups = dissectIdentity(wid);  //ends up as an arraylist of strings

    //Retrieves User.Groups to a variable by casting it to a collection

 

    string idHeader = "User : " + wid.Name;

    string adHeader = "ADGroups : " + adgroups[0];

    for(int i = 1; i < adgroups.count; ++i){

        adHeader += ", " + adgroups;

    }

 

    HttpWebRequest req = getHttpWebRequest (Request.url) as HttpWebRequest; // b/c it gives WebRequest

    req.addHeader(idHeader);

    req.addHeader(adHeader);

    Response.send(req.getResponse());

}

   

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to post
Share on other sites

String manipulation can be a sore point... and you a sore point there.  
 

adHeader += ", " + adgroups;

You should be using a StringBuilder in this instance.  Look up System.Text.StringBuilder.

 

I would also be curious what dissectIdentity would look like.  It also has potential performance issues.  Don't forget that System.String.Split exists.

Link to post
Share on other sites

1 hour ago, savstars said:

String manipulation can be a sore point... and you a sore point there.  
 


adHeader += ", " + adgroups;

You should be using a StringBuilder in this instance.  Look up System.Text.StringBuilder.

 

I would also be curious what dissectIdentity would look like.  It also has potential performance issues.  Don't forget that System.String.Split exists.

User.Groups returns a generic collection. All I do in that method is cast it to an arraylist and return it. I'll try the Stringbuilder in the morning though.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to post
Share on other sites

24 minutes ago, Erik Sieghart said:

You can time unit tests to diagnose which part of the code is chugging.

I haven't figured out yet how to do that in the context of an asp.net application. Because of the thread pools and various contexts the test results come out fuzzy, sporadic, and worthless. I'm currently researching it.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to post
Share on other sites

13 hours ago, savstars said:

If you're still having problems, just let me know.

 

7 hours ago, madknight3 said:

Could the extra time just be overhead added from the framework? What response time would you get if you were to respond with a hardcoded value and not do any actually work for the request?

Changing to stringbuilder did shave 0.02 seconds, and it'll shave comparatively more for people with more ad groups than me (seriously, why 213 ad groups?!), but I'm still sitting at 0.37 seconds for a response. I've tried forcing the project to target x64 to see if that might shrink the binary and cut out any instruction dispatching overhead, but then I get exceptions about missing dependencies (screw you Microsoft and your ambiguous 32/64-bit DLL names!!!).

 

What's the best way to post code projects? I tried posting a rar, but that's not allowed. I assume I'all have to put it up on github.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to post
Share on other sites

Sorry for the delay in my response, but, here is something I missed.  When you take your performance samples, make sure you are not doing it on the first execution since IIS has started, or been reset.  The JIT compiler spends time compiling the IL code to binary code on the first execution.  Make sure you are taking your samples in the second or following executions.

Link to post
Share on other sites

1 minute ago, savstars said:

Sorry for the delay in my response, but, here is something I missed.  When you take your performance samples, make sure you are not doing it on the first execution since IIS has started, or been reset.  The JIT compiler spends time compiling the IL code to binary code on the first execution.  Make sure you are taking your samples in the second or following executions.

Yeah, I hit that pitfall, and the performance figures are an average of 7 runs post-reset.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to post
Share on other sites

Get rid of standard MVC controllers, write a HttpListener server instead, or at least use SignalR, standard MVC sucks for performance. Otherwise make sure your allocations are at minimal, not just because of little performance gain in your case, but to avoid GC as much as possible, that kind of stuff, you get the idea, I don't think that's an issue for you.

Link to post
Share on other sites

5 minutes ago, DevBlox said:

Get rid of standard MVC controllers, write a HttpListener server instead, or at least use SignalR, standard MVC sucks for performance. Otherwise make sure your allocations are at minimal, not just because of little performance gain in your case, but to avoid GC as much as possible, that kind of stuff, you get the idea, I don't think that's an issue for you.

Can you get the User's Windows ADGroups easily this way? That's the crux of the functionality we need. Anything else can be stripped away as long as this remains in tact.

 

If I can't get it by context, I'd happily accept a tutorial for writing the protocol to get them. I can learn quickly as long as I have resources, and the weekend is nearly here, so it's the perfect opportunity to test it out.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to post
Share on other sites

6 minutes ago, patrickjp93 said:

Can you get the User's Windows ADGroups easily this way? That's the crux of the functionality we need. Anything else can be stripped away as long as this remains in tact.

It's definitely not "just as easily" with HttpListener, it will need some manual header fetching (and possibly parsing) to achieve this, past that, you should be able to find an easy way. SignalR might be a bit faster to deploy, because it's API is mostly the same if not identical to ASP.NET, though I can't tell you for sure, I've never done anything authentication/etc with it, it might take some playing around.

Link to post
Share on other sites

24 minutes ago, DevBlox said:

It's definitely not "just as easily" with HttpListener, it will need some manual header fetching (and possibly parsing) to achieve this, past that, you should be able to find an easy way. SignalR might be a bit faster to deploy, because it's API is mostly the same if not identical to ASP.NET, though I can't tell you for sure, I've never done anything authentication/etc with it, it might take some playing around.

Well, thank you for the suggestions regardless. Leads are leads.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×