473,748 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DB optimisation vs OOP layer separation

Hi,

I'm facing a code-optimisation issue on an asp.net/vb.net/SQL Server 2000
project. A web page containing not much more than 3 DropDownLists is taking
nigh on 6 seconds to load, because each ddl opens up a separate connection
to the DB, pulls out its data, and closes its own connection before the next
ddl repeats the process.

The code to handle each DDL's connection to the DB is packaged in an object
(presentation-layer code below); two of the hits go via a Person object, and
one via a User object. Both these objects are separated into a business
layer and a data layer.

My optimisation goal is to have all these three DB hits done on just one DB
connection. The only way I can think of doing this would be:

* create a connection object in the presentation layer (more likely, an
SqlCommand object which contains an open connection),
* pass this open connection to
Person.GetAllAc tiveNonIntroduc ersOrderBy("Las tName", "ASC")
* the presentation layer gets the open connection back from
Person.GetAllAc tiveNonIntroduc ersOrderBy("Las tName", "ASC"), laden with data
* the pres layer takes out the data, fills up DDL1 with it, and passes the
still-open-connection to Wec.User.GetAll OrderBy("LastNa me", "DESC")
* the open connection comes back once more to the presentation layer, laden
with the second batch of data
* DDL2 is filled up with this data, and the process repeats for DDL3
* once the pres layer has got all the necessary data it kills the connection

I dare say I could adapt the various Business and Data Layer routines to
handle this. My main worry is about violating the OOP principle of layer
separation - if I'm going to start creating SqlConnections / SqlCommands in
my *presentation layer*, I might as well slit my OOP wrists right now....

Any input welcome!

TIA,

JON
'DDL1
ddlIntroducerNa mes.DataSource =
Person.GetAllAc tiveNonIntroduc ersOrderBy("Las tName", "ASC")
ddlIntroducerNa mes.DataTextFie ld = "WholeName"
ddlIntroducerNa mes.DataValueFi eld = "PersonID"
ddlIntroducerNa mes.DataBind()

'DDL2
ddlWECReps.Data Source = Wec.User.GetAll OrderBy("LastNa me", "DESC")
ddlWECReps.Data TextField = "WholeName"
ddlWECReps.Data ValueField = "UserID"
ddlWECReps.Data Bind()

'DDL3
ddlIntroducedBy .DataSource = Person.GetAllAc tivesOrderBy("L astName", "ASC")
ddlIntroducedBy .DataTextField = "WholeName"
ddlIntroducedBy .DataValueField = "PersonID"
ddlIntroducedBy .DataBind()

Nov 20 '05 #1
8 1896
Opening and closing three connections shouldn't be your problem, unless
there aren't enough connections available in your pool. If there aren't
then you have a bigger problem than utilizing three connection objects. I
would suggest changing the Min and Max Pool Size to 150 and 300 respectively
(assuming you are running against a full version of SQL Server 2000).
Setting Connection Reset to false can help improve performance as long as
you realize the connection state isnt going to be reset each time you make a
database call.

In general Min Pooling is set to 0, and Max set to 100. These can be fairly
stringent when a server comes under load.

If none of these help, then I'd say do what is performant. There isn't much
you can do to keep your OO design as stringent as you've laid out here AND
share your connections.

--
Justin Rogers
DigiTec Web Consultants, LLC.
"Jon Maz" <jo****@surfeu. de.no.spam> wrote in message
news:Oo******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I'm facing a code-optimisation issue on an asp.net/vb.net/SQL Server 2000
project. A web page containing not much more than 3 DropDownLists is taking nigh on 6 seconds to load, because each ddl opens up a separate connection
to the DB, pulls out its data, and closes its own connection before the next ddl repeats the process.

The code to handle each DDL's connection to the DB is packaged in an object (presentation-layer code below); two of the hits go via a Person object, and one via a User object. Both these objects are separated into a business
layer and a data layer.

My optimisation goal is to have all these three DB hits done on just one DB connection. The only way I can think of doing this would be:

* create a connection object in the presentation layer (more likely, an
SqlCommand object which contains an open connection),
* pass this open connection to
Person.GetAllAc tiveNonIntroduc ersOrderBy("Las tName", "ASC")
* the presentation layer gets the open connection back from
Person.GetAllAc tiveNonIntroduc ersOrderBy("Las tName", "ASC"), laden with data * the pres layer takes out the data, fills up DDL1 with it, and passes the
still-open-connection to Wec.User.GetAll OrderBy("LastNa me", "DESC")
* the open connection comes back once more to the presentation layer, laden with the second batch of data
* DDL2 is filled up with this data, and the process repeats for DDL3
* once the pres layer has got all the necessary data it kills the connection
I dare say I could adapt the various Business and Data Layer routines to
handle this. My main worry is about violating the OOP principle of layer
separation - if I'm going to start creating SqlConnections / SqlCommands in my *presentation layer*, I might as well slit my OOP wrists right now....

Any input welcome!

TIA,

JON
'DDL1
ddlIntroducerNa mes.DataSource =
Person.GetAllAc tiveNonIntroduc ersOrderBy("Las tName", "ASC")
ddlIntroducerNa mes.DataTextFie ld = "WholeName"
ddlIntroducerNa mes.DataValueFi eld = "PersonID"
ddlIntroducerNa mes.DataBind()

'DDL2
ddlWECReps.Data Source = Wec.User.GetAll OrderBy("LastNa me", "DESC")
ddlWECReps.Data TextField = "WholeName"
ddlWECReps.Data ValueField = "UserID"
ddlWECReps.Data Bind()

'DDL3
ddlIntroducedBy .DataSource = Person.GetAllAc tivesOrderBy("L astName", "ASC") ddlIntroducedBy .DataTextField = "WholeName"
ddlIntroducedBy .DataValueField = "PersonID"
ddlIntroducedBy .DataBind()

Nov 20 '05 #2
Hi Justin,

Thanks for your comments. In this case, it can't be a pool issue - the page
in question is still in development on my local machine, so the server is
suffering under a maximum strain of one concurrent user (me).

I'm still relatively new to OOP and n-tier architecture, and I'm a bit
shocked at the thought that there might be no OOP solution to this issue
that keeps the layers separate. For the moment, I am still (naively?)
hoping that someone will post along the lines of: "oh yes, that's a common
situation, and here's the standard way round it"...

Fingers crossed,

JON
Nov 20 '05 #3
Is it slow when the page is first loaded or is it slow every time?
If it's slow only the first time, I wouldn't worry about it, as it will only
affect the first user hitting the page.
"Jon Maz" <jo****@surfeu. de.no.spam> wrote in message
news:Oo******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I'm facing a code-optimisation issue on an asp.net/vb.net/SQL Server 2000
project. A web page containing not much more than 3 DropDownLists is taking nigh on 6 seconds to load, because each ddl opens up a separate connection
to the DB, pulls out its data, and closes its own connection before the next ddl repeats the process.

The code to handle each DDL's connection to the DB is packaged in an object (presentation-layer code below); two of the hits go via a Person object, and one via a User object. Both these objects are separated into a business
layer and a data layer.

My optimisation goal is to have all these three DB hits done on just one DB connection. The only way I can think of doing this would be:

* create a connection object in the presentation layer (more likely, an
SqlCommand object which contains an open connection),
* pass this open connection to
Person.GetAllAc tiveNonIntroduc ersOrderBy("Las tName", "ASC")
* the presentation layer gets the open connection back from
Person.GetAllAc tiveNonIntroduc ersOrderBy("Las tName", "ASC"), laden with data * the pres layer takes out the data, fills up DDL1 with it, and passes the
still-open-connection to Wec.User.GetAll OrderBy("LastNa me", "DESC")
* the open connection comes back once more to the presentation layer, laden with the second batch of data
* DDL2 is filled up with this data, and the process repeats for DDL3
* once the pres layer has got all the necessary data it kills the connection
I dare say I could adapt the various Business and Data Layer routines to
handle this. My main worry is about violating the OOP principle of layer
separation - if I'm going to start creating SqlConnections / SqlCommands in my *presentation layer*, I might as well slit my OOP wrists right now....

Any input welcome!

TIA,

JON
'DDL1
ddlIntroducerNa mes.DataSource =
Person.GetAllAc tiveNonIntroduc ersOrderBy("Las tName", "ASC")
ddlIntroducerNa mes.DataTextFie ld = "WholeName"
ddlIntroducerNa mes.DataValueFi eld = "PersonID"
ddlIntroducerNa mes.DataBind()

'DDL2
ddlWECReps.Data Source = Wec.User.GetAll OrderBy("LastNa me", "DESC")
ddlWECReps.Data TextField = "WholeName"
ddlWECReps.Data ValueField = "UserID"
ddlWECReps.Data Bind()

'DDL3
ddlIntroducedBy .DataSource = Person.GetAllAc tivesOrderBy("L astName", "ASC") ddlIntroducedBy .DataTextField = "WholeName"
ddlIntroducedBy .DataValueField = "PersonID"
ddlIntroducedBy .DataBind()

Nov 20 '05 #4
Every time, I'm afraid...
Nov 20 '05 #5
Hi Fergus,

A Connection Cache class, eh? Intriguing, sounds like just the kind of
thing I'm after... Any chance of a code snippet, or perhaps a link or two,
to get me started?

Cheers,

JON
Nov 20 '05 #6
Hi Jon,

I made it up ;-)

But I can do one for you later. You may get one or two in the meantime.

Later, Dude,
Fergus
Nov 20 '05 #7
Hi Jon,

Here's a bit of code that may be useful:

'============== =============== =============== =============== ==============
'The following implements a very simple object cache.
'In this case the cached object is an SqlConnection.
'
'The class is told how many times an object
'will be used before it is to be discarded.
'On creation (initial connect) the object's count is set.
'For each disconnection, the count is decremented.
'The object is only released when the count goes to zero.

'UNTESTED AND INCOMPLETE.
'REQUIRES ERROR HANDLING.

Imports System.Data.Sql Client

Public Class clsConnectionCa che

'The number of times a new connection gets used before being discarded.
Public Shared iNumTimesToReus e As Integer

Private Sub New 'No instantiation.
End Sub

'============== =============== =============== =============== ==============
Private Class CachedConnectio n
Public sConnString As String
Public oSqlConnection As SqlConnection
Public iUsageCount As Integer
End Class

Private Shared m_aloConnection s As ArrayList 'of CachedConnectio n

'============== =============== =============== =============== ==============
Public Function Connect (sConnString As String) As SqlConnection
Dim oConnection As CachedConnectio n

'Look for the connection string in the cache.
For Each oConnection In m_aloConnection s
If oConnection.sCo nnString = sConnString Then
'Return the cached SqlConnection.
Return oConnection.oSq lConnection
End If
Next
'The connection string was not found and
'therefore the SqlConnection is not cached.

'Create a new CachedConnectio n.
oConnection = New CachedConnectio n
oConnection.oSq lConnection = New SqlClient.SqlCo nnection (sConnString)
oConnection.sCo nnString = sConnString
oConnection.iUs ageCount = iNumTimesToReus e

'Add it to the cache.
m_aloConnection s.Add (oConnection)

'Return the new SqlConnection.
Return oConnection.oSq lConnection
End Function

'============== =============== =============== =============== ==============
Public Sub Disconnect (oSqlConnection As SqlConnection)
Dim oConnection As CachedConnectio n

'Look for the SqlConnection in the cache.
For Each oConnection In m_aloConnection s
If oConnection.oSq lConnection Is oSqlConnection Then
'Another disconnect - reduce the usage count.
oConnection.iUs ageCount = oConnection.iUs ageCount - 1

'Is it the last?
If oConnection.iUs ageCount = 0 Then
'Do disconnect stuff here.
oSqlConnection. Close()
oSqlConnection. Dispose()
m_aloConnection s.Remove (oConnection)
End If

Return
End If
Next
'The SqlConnection was not found.
'Throw a wobbly.
End Sub

End Class
'============== =============== =============== =============== ==============
Regards,
Fergus
Nov 20 '05 #8
That's excellent Fergus, just what I need to get me started!

Thanks for all the help,

JON
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
2979
by: Griff | last post by:
Hi there I'm after some suggestions as to how one might best separate form and content in a normal run-of-the-mill web application. I'm sure whole bookshelves have been written on this, but I could use some pointers as to the most helpful roads to investigate. The situation I'd like to end up with is the ability to split web development work into two halves - programmers writing back-end logic, and web designers building the look and...
0
993
by: Pheller | last post by:
The time tracker example adds pieces of the Data Access layer to the business Object. Shouldn't there be a third layer that communicates with the DAL, Business Object and Presentation layer call the Object Declarations (Data Tranfer Object)? www.asp.net example 2/24/04 "Creating Collections for Data Binding and Serialization" is more in line with this than the time tracker example. Which is the preferred methodolgy that should be...
4
1971
by: MG | last post by:
A Newbie question perhaps, but here goes: Is it possible to seaprate the presentatieon layer, i.e., the html, from the application itself. For example, our developer has told us that we cannot do immeidate changes to user interface becasue the presentaion layer is bound up with the rest of the dll and to eextract that out of the app, would take ages. and so any changes would be incorproated into the next buiild compilation.
16
1490
by: simonwittber | last post by:
Hello People. I've have a very tight inner loop (in a game app, so every millisecond counts) which I have optimised below: def loop(self): self_pool = self.pool self_call_exit_funcs = self.call_exit_funcs self_pool_popleft = self.pool.popleft self_pool_append = self.pool.append
11
9112
by: Michael Rodriguez | last post by:
I have a windows form that makes a call to my BLL to get some data. The windows form has a progress bar component that I would like updated as the data retrieval takes place. However, strictly speaking, the BLL is not supposed to know anything about the presentation layer. Also, since the presentation layer has a reference to the BLL, it won't let me add a reference to the presentation layer from the BLL, it complains about a "circular...
2
2213
by: headware | last post by:
I'm relatively new to ASP.NET and ADO.NET, but I have a basic design question regarding the use of web services and APS.NET applications. Right now we have an application that uses web services to access the database layer. However, the code works in a pretty cumbersome and ungeneric way. Basically every query, update, and insert has its own function. So you see a lot of functions like webService.InsertCustomer(name, age, phone); or...
8
8554
by: Rashmi | last post by:
Hi! I am new to web services. AFAIK, the advantages of using web services are : interoperable, easy integration and reuse, text based protocols and data formats - SOAP,WSDL,XML. Also, I read this article: http://www.theserverside.net/articles/showarticle.tss?id=Top5WSMistakes I agree with everything this article says. Is there anyone (or anylink) which proves otherwise? I have read quite a few times about using web
2
2361
by: dkode | last post by:
Hello, I am laying out the architecture for a very large website that will scale to a very large degree. I have a couple of questions before I attempt to go and implement a Broker/Persistence Layer. 1. With a broker layer, does this layer sit at the same level as the Business Layer? So to speak, the presentation layer has knowledge of
5
1363
by: Jens Jensen | last post by:
Hello, Does anyone know anything about how to optimise asp.net 2.0 pages for search engines? I'm thinking of a programmatic way of mapping sitemap structure to pages meta tags. Well it can always be done i'm just wondering of smart ways of doing it.
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.