Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

Before you say "Because your code takes that long to run", just look:

This is running on my local machine.

I have recently added logging. The log takes DataTime.Now and adds that to the string to be logged. It then puts that string into a queue to be written in the log file. This means that the log might not be updated immediately, but the times are accurate.

I have a web service to consume requests (big objects get thrown at it. About 2-6Kb).
I have a test harness that throws objects at it constantly so I can try to break it (still trying).

My logging in my web service is as follows:
C#
public Response SendDetails(Details details, string ident, Guid accessGuid, object syncState)
{
    string requestIdStr = "";
    int requestId;
    if (int.TryParse(syncState.ToString(), out requestId))
        requestIdStr = string.Format("{0:D4}: ", requestId);

    //Log before all the work
    Logs.Log(string.Format("{1}New notice from {0}", ident, requestIdStr));
    int responseId = 0;
    try
    {
        if [Boring validation stuff ]
        else
        {
            ThreadPool.QueueUserWorkItem(delegate
            {
                [The Heavy Lifting work]
            });
        }
        //log after all the work (just before return)
        Logs.Log(string.Format("{2}Responded to New notice from {0} with:{1}", ident, _errorCodes[responseId], requestIdStr));
        return _errorCodes[responseId];
    }
    catch (Exception exception)
    {
        //This hasn't happened in a while.
        Logs.LogException(exception);
        return new Response("x99", exception.ToString());
    }
}


My logging in my test harness is as follows:
C#
//Log just before and after web call
Logs.Log("{0:D4}: Sending to secure access service", userstate);
client.SendDetails(details, "x", Guid.Parse([NDA]),userstate);
Logs.Log("{0:D4}: Sent to secure access service", userstate);



So: The service log says:
12:03:37:918	SendDetails     '0009: New notice from x'
12:03:37:920	SendDetails     '0009: Responded to New notice from x with:[x00] Success'

So 2 milliseconds to do all the work

The testharness log:
12:03:37:912	WriteLine             '0009: Sending to secure access service'
12:03:48:858	WriteLine             '0009: Sent to secure access service' 



To conclude:
It takes 0.006 seconds to send the request, 0.002 seconds to process the request and then ~11 seconds to send the response?

What the heck?

PS: In case you think that Response is at fault, here is that class too:
C#
[DataContract]
public class Response
{
    [DataMember]
    public string ResponseCode { get; set; }
    [DataMember]
    public string ResponseDetail { get; set; }

    public Response(string responseCode, string responseDetail)
    {
        ResponseCode = responseCode;
        ResponseDetail = responseDetail;
    }

    public override string ToString()
    {
        return string.Format("[{0}] {1}", ResponseCode, ResponseDetail);
    }
}


UPDATE: i have run the service trace as Richard D suggested:
Some are quick: 
Message Sent - 12:41:51.3914836
Message Received - 12:41:51.3994892

Some, not so much
Message Sent - 13:42:22:23798318
Message Received - 13:42:40.6326977

Is there anything else I can glean from these?
Posted
Updated 26-Jun-15 2:58am
v3
Comments
Richard Deeming 26-Jun-15 8:26am    
Try configuring tracing[^] at both ends, and then use the service trace viewer[^] to try to work out where the bottleneck is.
Andy Lanng 26-Jun-15 8:45am    
Ok - Thanks for that, I was unaware of it ^_^

I don't see any new info there, tho - I'll update by question with what it's found
j snooze 26-Jun-15 17:06pm    
have you tried using fiddler? This is great for showing your network calls and any post and response data. Might help you dig a little deeper.
Andy Lanng 27-Jun-15 7:13am    
I have. it said nothing extra. my response class is tiny ("x00: Success")

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900