Re: Is 'connection pooling' obsolete given MARs? by Angel
Angel
Thu Feb 05 23:58:30 CST 2004
Comments Inline, thanks for the feedback.
--
Angel Saenz-Badillos [MS] Managed Providers
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
"Lecture Snoddddgrass" <maley@hamburg.fry> wrote in message
news:uSnVrzE7DHA.1948@TK2MSFTNGP12.phx.gbl...
> Thanks for the great information. I have some follow-up questions for
> you:
>
> > Mars is not thread safe, you cannot create one connection and execute
MARS
> > commands on separate threads.
>
> So let's say that I have 50 SqlCommand objects in an array that need
to
> be executed. Would I be able to loop through that array calling
> BeginExecuteNonQuery() on each one even if each SqlCommand were associated
> with the same connection?
Yes, you would be able to do this because BeginExecuteNonQuery is a true
async call. It does not start a new thread in your process so all fifty
commands would be running in the same thread. You still have to consume the
results on the same thread though, so you can waitone /waitall and you can
poll, but you cannot use callbacks directly. You will run into problems if
you try to use the Callback option since callbacks happen in a different
thread. There are probably going to be workarrounds for this like calling
back to the main thread from the callback.
> > Mars multiplexes the connection result set buffer, eventually it is
going
> to
> > be more expensive to multiplex than to open a new connection.
>
> What does "multiplex" mean?
Each connection has a tds buffer associated with it, think of it as a
bi-directional queue where both the server and the client push data to the
other. This queue can only be used in one direction at a time which is why
up to now we have not been able to have multiple resultsets. With Mars we
have modified this buffer to work as if it was more than one buffer, we have
multiplexed it. This is not an expensive operation but eventually it becomes
more expensive to make the one buffer work as n buffers than to open a new
connection.
> > Mars executes synchronously on the server.
>
> Ok, I think that's the deal-killer right there. So let's say that I
use
> MARS to execute 50 queries on the same connection. The first query takes
10
> seconds to run. The other 49 queries could be performed in .10 seconds.
> You're saying that the 49 quickie queries would have to wait until the
first
> one finishes? Just want to make sure I understand you.
This could be the worst case scenario yes, all MARS sessions are sharing the
same process space.
> > Likely MARS scenarios:
>
> Well, my scenario is a bit different than what you've described. I
have
> a service that gets hit with hundreds of requests per second. Each request
> comes in on a thread-pool thread. Some of these requests require a SELECT
> query against SQL Server. As it stands, these SELECT queries can't be done
> in a true async fashion. They block. Given that there are only 25 threads
in
> the thread pool, if I'm working on 25 requests that each need to access
SQL
> Server, and each of these threads is blocked waiting for SQL Server to
> respond, my service is just sitting idly blocking unable to respond to
other
> requests that are coming in. A more efficient way to handle this would be
if
> when a request came in I could call some sort of BeginFill() [to fill a
> dataset] method which would immediately return and then would call a
> callback method when the query is finished. That way, my request handler
> thread wouldn't block. It would be returned to the pool to do other tasks
> and then when the query results were ready, I could deal with the results.
> What's really killing the scalability of my service right now is ADO.NET.
> Will ADO.NET 2.0 be able to help me with this problem? If so, I'll be very
> happy!
>
> Thanks!
>
That's a tough scenario I will have to take a longer look at it. There
should be a way to get async to work for you here, but it is probably not
going to be something off the shelf.