Presentation is loading. Please wait.

Presentation is loading. Please wait.

Communicating with the Outside. Hardware [Processor(s), Disk(s), Memory] Operating System Concurrency ControlRecovery Storage Subsystem Indexes Query.

Similar presentations


Presentation on theme: "Communicating with the Outside. Hardware [Processor(s), Disk(s), Memory] Operating System Concurrency ControlRecovery Storage Subsystem Indexes Query."— Presentation transcript:

1 Communicating with the Outside

2 Hardware [Processor(s), Disk(s), Memory] Operating System Concurrency ControlRecovery Storage Subsystem Indexes Query Processor Application

3 The ways applications accessing the Database System 4GL(fourth generation language) –Execute at high level resulting in small programs –Hider portability, different vendors offers different 4GLs Programming language + Call Level Interface –ODBC(Open DataBase Connectivity) for c/c++ –JDBC: Java based API, for Java –Database specific ODBC drivers: OCI (C++/Oracle), CLI (C++/ DB2) –Perl/DBI

4 API pitfalls Cost of portability –Layer of abstraction on top of ODBC drivers to hide discrepancies across drivers with different conformance levels. –Beware of performance problems in this layer of abstraction: Use of meta-data description when submitting queries, accessing the result set Iterations over the result set

5 ODBC vs. OCI ODBC vs. OCI on Oracle8iEE on Windows 2000 Iteration over a result set one record at a time. Prefetching is performed. Low OCI overhead when number of records transferred is small ODBC performs better when number of records transferred increases due to it’s good at prefetching.

6 Client-Server Mechanisms Connection pooling and multiplexing when multiple clients access a server Communication buffer on the database server. One per connection. –If a client does not consume results fast enough, then the server holds resources until it can output the result. –Data is sent either when the communication buffer is full or when a batch is finished executing. Small buffer – frequent transfer overhead Large buffer – time to first record increases. No actual impact on a 100 Mb network. More sensitive in an intranet with low bandwidth.

7 Communication buffer

8 Harmful small objects authorized(user, type) doc(id, type, date) What are the document instances a user can see? SQL: select doc.id, doc.date from authorized, doc where doc.type = authorized.type and authorized.user = If documents and doctypes are encapsulated in objects, the risk is the following: –Find types t authorized for user input select doc.type as t from authorized where user = –For each type t issue the query select id, date from doc where type = ; –The join is executed in the application and not in the DB!

9 Tuning the Application Interface Avoid user interaction within a transaction Minimize the number of roundtrips between the application and the database Retrieve needed columns only Retrieve needed rows only Minimize the number of query compilations

10 Avoid User Interaction within a Transaction User interaction within a transaction forces locks to be held for a long time. Careful transaction design (possibly transaction chopping) to avoid this problem.

11 Minimize the Number of Roundtrips to the Database Rule of thumb: crossing the interface between the application and the database server is costly Avoid Loops: –Application programming languages offer looping facilities (SQL statements, cursors, positioned updates) Positioned updates: ODBC allows updating the rows that are obtained as the result of a query, this forces the processing of updates one row at a time –Rigid object-oriented programming might force such loops.

12 Avoid External Loops No loop: sqlStmt = “select * from lineitem where l_partkey <= 200;” odbc->prepareStmt(sqlStmt); odbc->execPrepared(sqlStmt); Loop: sqlStmt = “select * from lineitem where l_partkey = ?;” odbc->prepareStmt(sqlStmt); for (int i=1; i<200; i++) { odbc->bindParameter(1, SQL_INTEGER, i); odbc->execPrepared(sqlStmt); }

13 Avoid External Loops SQL Server 2000 on Windows 2000 Crossing the application interface has a significant impact on performance Let the DBMS optimize set operations Fetch 2000 records Loop: 200 queries No loop: 1 query Crossing the application interface too often hurts performances.

14 Avoid Cursors No cursor select * from employees; Cursor DECLARE d_cursor CURSOR FOR select * from employees; OPEN d_cursor while (@@FETCH_STATUS = 0) BEGIN FETCH NEXT from d_cursor END CLOSE d_cursor go

15 Avoiding Cursors Cursors are terribly slow in almost all systems Using the cursor, records are transmitted from the database server to the application one at a time. Query fetches 200000 56 bytes records Response time is a few seconds with a SQL query and more than an hour iterating over a cursor.

16 summary


Download ppt "Communicating with the Outside. Hardware [Processor(s), Disk(s), Memory] Operating System Concurrency ControlRecovery Storage Subsystem Indexes Query."

Similar presentations


Ads by Google