I have written a web service that retrieves 4700+ rows of data from SQL. While it comes out around 15MB of data, it takes as long as 10 seconds for the front-end webpage to load the data into the Gridview. (SQL, Web Service
and Client app are on the same big honkin' server) In investigating my options I have come to believe that I might be spawning multiple copies of the dataset (though I have no real evidence to support this) which has directed me to attempt it as a singleton,
then use a webcache to keep the data local and fast.
My questions are:
1) how many instances of a dataset are ever created if the webservice creates it and merely hands it off to the client through the webproxy? I haven't found the definitive doc that talks about this.
2) Does anyone have an example of how to implement a webservice/webmethod that returns a dataset using the Singleton design? i have found several examples, but they all either return an entire class or simply don't work for
a dataset (at least not that I've been able to get working so far)
3) Has anyone encountered any problems building a webcache with Beta 2? I'm getting errors telling me that "Caching" is not part of the System.Web namespace and of course it is.
I have written a web service that retrieves 4700+ rows of data from SQL. While it comes out around 15MB of data, it takes as long as 10 seconds for the front-end webpage to load the data into the Gridview. (SQL, Web Service
and Client app are on the same big honkin' server) In investigating my options I have come to believe that I might be spawning multiple copies of the dataset (though I have no real evidence to support this) which has directed me to attempt it as a singleton,
then use a webcache to keep the data local and fast.
Wow, 4700+ rows and only 10 seconds? I'd say that's doing good, considering how much work you're asking this infrastructure to do. The DataSet wasn't designed to be pushed too far beyond this size. Although, I believe they have made some improvements in
performance in 2.0.
Johnmccrae
1) how many instances of a dataset are ever created if the webservice creates it and merely hands it off to the client through the webproxy? I haven't found the definitive doc that talks about this.
Every call into the webservice will give you back a new set of results in the client.
Johnmccrae
2) Does anyone have an example of how to implement a webservice/webmethod that returns a dataset using the Singleton design? i have found several examples, but they all either return an entire class or simply don't work for
a dataset (at least not that I've been able to get working so far)
So are you asking how to implement the webservice as a singleton? The .NET web service implementation creates an instance of your ASMX handler per request, but that's an implementation detail. To keep a single copy of your data you can make the webservice
store all of its state in static variables and then all requests can pull from those. This now introduces multithreaded issues if that state is being updated in the webservice.
Johnmccrae
3) Has anyone encountered any problems building a webcache with Beta 2? I'm getting errors telling me that "Caching" is not part of the System.Web namespace and of course it is.
How are you trying to access it? The Cache class is in the System.Web.Caching namespace and should be accessible from HttpContext.Current.Cache (or HttpRuntime.Cache).
Thanks for the help. I wasn't too sure what the performance should be like and was thinking that the dataset should both abstract me from the direct SQL read and also speed it up.
So merely creating the dataset object as static effectively makes it a singleton? Interesting, I'll have to play with that. My reading about this also talked about threading, I'll have to look into this too.
For the webcache, I was simply adding it to my application namespace a la:
using System.Web.Caching
^^^^^ getting an error here telling me that Caching is not part of the System.web namespace
It turned out to be Stupid Dev trick #2. I *didn't* have a reference to the System.web.dll in the project settings. It all works now. Thanks for the guidance.
Slightly related to this topic - does anyone know the performance implications of using the singleton pattern for a web service proxy? In other words, is there any gain from wrapping a web service and having a single instance satisfy all requests verses
opening and closing request specific instances?
Johnmccrae
Member
40 Points
9 Posts
How To: Singleton Web Service
Apr 30, 2005 03:34 AM|LINK
Greetings,
I have written a web service that retrieves 4700+ rows of data from SQL. While it comes out around 15MB of data, it takes as long as 10 seconds for the front-end webpage to load the data into the Gridview. (SQL, Web Service and Client app are on the same big honkin' server) In investigating my options I have come to believe that I might be spawning multiple copies of the dataset (though I have no real evidence to support this) which has directed me to attempt it as a singleton, then use a webcache to keep the data local and fast.
My questions are:
1) how many instances of a dataset are ever created if the webservice creates it and merely hands it off to the client through the webproxy? I haven't found the definitive doc that talks about this.
2) Does anyone have an example of how to implement a webservice/webmethod that returns a dataset using the Singleton design? i have found several examples, but they all either return an entire class or simply don't work for a dataset (at least not that I've been able to get working so far)
3) Has anyone encountered any problems building a webcache with Beta 2? I'm getting errors telling me that "Caching" is not part of the System.Web namespace and of course it is.
Thanks in advance for any and all comments
Cheers
John
BrockAllen
All-Star
27554 Points
4912 Posts
MVP
Re: How To: Singleton Web Service
May 01, 2005 03:37 PM|LINK
Wow, 4700+ rows and only 10 seconds? I'd say that's doing good, considering how much work you're asking this infrastructure to do. The DataSet wasn't designed to be pushed too far beyond this size. Although, I believe they have made some improvements in performance in 2.0.
Every call into the webservice will give you back a new set of results in the client.
So are you asking how to implement the webservice as a singleton? The .NET web service implementation creates an instance of your ASMX handler per request, but that's an implementation detail. To keep a single copy of your data you can make the webservice store all of its state in static variables and then all requests can pull from those. This now introduces multithreaded issues if that state is being updated in the webservice.
How are you trying to access it? The Cache class is in the System.Web.Caching namespace and should be accessible from HttpContext.Current.Cache (or HttpRuntime.Cache).
-Brock
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
Johnmccrae
Member
40 Points
9 Posts
Re: How To: Singleton Web Service
May 01, 2005 11:20 PM|LINK
Brock,
Thanks for the help. I wasn't too sure what the performance should be like and was thinking that the dataset should both abstract me from the direct SQL read and also speed it up.
So merely creating the dataset object as static effectively makes it a singleton? Interesting, I'll have to play with that. My reading about this also talked about threading, I'll have to look into this too.
For the webcache, I was simply adding it to my application namespace a la:
using System.Web.Caching
^^^^^ getting an error here telling me that Caching is not part of the System.web namespace
Thanks again for your help
Cheers
John
BrockAllen
All-Star
27554 Points
4912 Posts
MVP
Re: How To: Singleton Web Service
May 02, 2005 01:46 AM|LINK
Hmm, well it is :)
Do you have a reference to System.Web.dll? I don't see why you wouldn't, given your webservice.
-Brock
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
Johnmccrae
Member
40 Points
9 Posts
Re: How To: Singleton Web Service
May 08, 2005 10:03 PM|LINK
It turned out to be Stupid Dev trick #2. I *didn't* have a reference to the System.web.dll in the project settings. It all works now. Thanks for the guidance.
Cheers
John
optionDK
Member
275 Points
55 Posts
Re: How To: Singleton Web Service
Aug 21, 2005 10:59 PM|LINK
Read this article (http://msdn.microsoft.com/webservices/default.aspx?pull=/library/en-us/dnwebsrv/html/asmxremotesperf.asp) about performance with Webservices and you will be surprised about the performance penalty you get using Datasets. Try instead to use typed classes and you will gain a performance boost of 6-7 times ....
Happy programming
Henrik Sørensen, OPTION APS Denmark
brianfriedma...
Member
6 Points
3 Posts
Re: How To: Singleton Web Service
Sep 02, 2009 03:03 PM|LINK
Slightly related to this topic - does anyone know the performance implications of using the singleton pattern for a web service proxy? In other words, is there any gain from wrapping a web service and having a single instance satisfy all requests verses opening and closing request specific instances?
Thanks - just curious.
Brian