Tech Off Thread

13 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Is Windows caching my Web Service connections?

Back to Forum: Tech Off
  • User profile image
    Minh

    I notice in my WinForms app that makes a Web Service call that -- subsequent start-up after the 1st one are much faster -- something in the neighborhood of 100% faster.

    I'm guessing that Windows is caching a TCP connection needed for the Web Service call. I'd like to do some optimization on my app and ACTUALLY need to get rid of this cached connection (for now anyway).

    Is there such a call to "flush" the connection cache (if it were the case).

    PS.
    An IPCONFIG /RELEASE & /RENEW doesn't seem to do the trick. The app still starts up pretty quickly. (Damn you Windows Tongue Out)

    EDIT:
    Nevermind... A cold-boot seems not to work either. We are caching stuff on the Web Server too. That must be where the extra time is coming from -- establishing resources on the Web Server and not connection caching on the client. Interesting.

  • User profile image
    Sven Groot

    It could just be the JIT compiling of all the web services client proxy code, which happens only the first time you use it.

  • User profile image
    Minh

    Sven Groot wrote:

    It could just be the JIT compiling of all the web services client proxy code, which happens only the first time you use it.

    The JIT'ed code would only persist for the life-time of the process, right? So if I close Visual Studio or exited the .EXE, I'd have to re-JIT?

  • User profile image
    Sven Groot

    Yep, unless you use ngen. I'm not sure that's the cause of the speed diff you're seeing though.

  • User profile image
    Minh

    Sven Groot wrote:
    Yep, unless you use ngen. I'm not sure that's the cause of the speed diff you're seeing though.

    I'm noticing the speed up even after a process restart. I'm gonna bypass our server-side caching so I can guage it a bit better...

    UPDATE:
    I think there's definitely some connection caching going on now. I'm bypassing our caching mechanism, and the 1st Web Service call takes about 3 seconds. Sub-sequent Web Service call is 100 times faster -- and the speed increase survives process restarts too.

    UPDATE2:
    Damn. We're doing object pooling on this Web Service, too... so it's less clear now.

  • User profile image
    figuerres

    Minh wrote:
    I notice in my WinForms app that makes a Web Service call that -- subsequent start-up after the 1st one are much faster -- something in the neighborhood of 100% faster.

    I'm guessing that Windows is caching a TCP connection needed for the Web Service call. I'd like to do some optimization on my app and ACTUALLY need to get rid of this cached connection (for now anyway).

    Is there such a call to "flush" the connection cache (if it were the case).

    PS.
    An IPCONFIG /RELEASE & /RENEW doesn't seem to do the trick. The app still starts up pretty quickly. (Damn you Windows Tongue Out)

    EDIT:
    Nevermind... A cold-boot seems not to work either. We are caching stuff on the Web Server too. That must be where the extra time is coming from -- establishing resources on the Web Server and not connection caching on the client. Interesting.



    A few notes on webservice:

    when you create a "web service" proxy in your app it will make a connection and by default uses HTTP 1.1 keep-alive behavior.

    what I am doing more and more is to create and destroy the proxy for each call.

    I have seen the client try and use a connection that the server has dumped -- and the client then throws an "Underlying connection was closed" type of ex.


    if you want / need to there is an underlying web connection created by the call but dang if I know where to hook to get it!

    also on the server you can shut off the 1.1 keep-alive if you need to.


    so yes it keeps a connection, not really a "cashe" just a keep-alive
    that should be "Per Object" I think...

    also on the frst call you may be jit'ing the server side code....
    do you pre-compile the server code??  if not try that??
    (edit on a dev box and then deploy a non-updateable web)
    (the whole site will be in dll's w/o any lose class files then)

  • User profile image
    blowdart

    You'd think open sockets where tied to a process though.

    Have you tried TCPView to watch what's going on?

  • User profile image
    Minh

    figuerres wrote:

    when you create a "web service" proxy in your app it will make a connection and by default uses HTTP 1.1 keep-alive behavior.

    Ahh. That makes sense. Thanks for the info.

    figuerres wrote:
    what I am doing more and more is to create and destroy the proxy for each call.

    I have seen the client try and use a connection that the server has dumped -- and the client then throws an "Underlying connection was closed" type of ex.

    Really? I'm noticing a 3 seconds start-up time vs. 0.3 seconds (yeah, I goofed on that 100x speed up ... just 10x) when the connection's already made.

    Couldn't you just catch that exception instead of closing the connection each time?

  • User profile image
    Minh

    blowdart wrote:
    You'd think open sockets where tied to a process though.

    Have you tried TCPView to watch what's going on?
    You'd think so. I'll check to make sure though. Thanks for the tip.

  • User profile image
    blowdart

    Minh wrote:
    
    blowdart wrote:You'd think open sockets where tied to a process though.

    Have you tried TCPView to watch what's going on?
    You'd think so. I'll check to make sure though. Thanks for the tip.


    You have to love sysinternals Smiley

  • User profile image
    Minh

    blowdart wrote:
    Minh wrote:
    blowdart wrote:You'd think open sockets where tied to a process though.

    Have you tried TCPView to watch what's going on?
    You'd think so. I'll check to make sure though. Thanks for the tip.


    You have to love sysinternals Smiley

    I have to & I do... cuz it's confirmed. Keep-alive connections DO go away when the process go away.

  • User profile image
    figuerres

    Minh wrote:
    
    figuerres wrote:
    when you create a "web service" proxy in your app it will make a connection and by default uses HTTP 1.1 keep-alive behavior.

    Ahh. That makes sense. Thanks for the info.

    figuerres wrote: what I am doing more and more is to create and destroy the proxy for each call.

    I have seen the client try and use a connection that the server has dumped -- and the client then throws an "Underlying connection was closed" type of ex.

    Really? I'm noticing a 3 seconds start-up time vs. 0.3 seconds (yeah, I goofed on that 100x speed up ... just 10x) when the connection's already made.

    Couldn't you just catch that exception instead of closing the connection each time?



    thats also an idea I am toying with.


    some info on what I have going on:

    an app that is partly a Point of Sale App and has other system functions like taking deposits etc...


    runs all day long.

    may not call some functions all day long.

    a few things get used a  lot for a while and then not at all for a while.

    the web service proxy classes do not really expose the info I would like to see and I hate to "Code by Exception"


    I'd kinda like to have a"Generic Like" wrapper for any web call to check the connection and create a new one if the old one was lost.
    to only throw an Ex when the remote server was really not reachable.

    the other route -- that seems to be more stable but perhaps not as fast. is to treat the ws like a db connection:
    create it
    use it
    toss it

    get in fast and get out fast and never assume any "state"

    this way I can trap "web errors" as "failure to connect"
    and I should not have other timeout / connection closed cases any more.

    I wish they had exposed a set of "Connect()" and "Close()" methods and some kind of "Time" value to tell how long the class has been sitting there with an open tcp client.

    that would help in some of this....


  • User profile image
    samjudson

    Could it be the JIT of the web service (on the server, as opposed to the client) that is slow the first time, and faster from there on in...?

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.