Presentation is loading. Please wait.

Presentation is loading. Please wait.

3-tier application architecture A technical view

Similar presentations


Presentation on theme: "3-tier application architecture A technical view"— Presentation transcript:

1 3-tier application architecture A technical view
Database Management 3-tier application architecture A technical view

2 Themes Architecture : The large scale structure of a system, especially a computer system Communications : The interaction between components Database: enabling applications with database driven applications

3 Displaying a Web page in a Browser
Click on a link on a page <a href= URL is decoded: protocol:://host/file Host is decoded using DNS to get the host IP address …. Page requested from HTTP server on the host (apache) Page is returned HTML codes determine how text is rendered If page contains links e.g. <img src=red.gif>, browser must repeat the same process on each

4 Dynamic Web page needed when:
consistent look and feel on each page of a large site data is derived from a database depends on real time pages depend on user choice business transactions e.g. e-commerce…

5 3-tier architecture A Presentation layer using Browser technology
An Application layer using a web application server platform + application programs A Persistence layer using a relational database or other data store technology

6 Bus timetable BUS (Level 1 Diagram) users a information need
presentation layer 1 application 2 HTTP requests persistance 3 SQL requests tables HTML files information service providers b timetables Browser such as IE6, FoxFire Apache or MS IIS server + PHP MySQL RDBMS Bus timetable

7 Presentation layer arch
Issue request to remote server accept the returned HTML (or JPEG..) file render (i.e. create a 2-d image ) the HTML allow plug-ins to handle new file types execute client-side scripts in JavaScript support interaction between client-side scripts and the web page accept user input via a variety of controls on a form

8 Persistence layer arch
support application interaction with the database using standard languages e.g SQL queries and table returns define and modify the data structures (e.g. tables) themselves ( the Database Schema) insert, update and delete data maintain data persistently, with backup and recovery handle transactions to support concurrent access to the database via locking et optimise access by compilation of queries, indexing, replication of tables etc.

9 Application Layer arch
accepting requests from the Presentation layer interpreting the requests according to business rules and past transactions from this client requesting the appropriate data from the Persistence layer using SQL Handling the returned result codes and tables computing derived data creating the HTML (or GIF, MIDI..) for the page providing run-time support for: thousands of concurrent users compilation to machine code multi-threading [ allow multiple processes to run concurrently] caching [holding results in a temporary store to reduce re-calculation]

10 Web Application Platforms
Server side includes - files with a .shtml extension Cgi using Perl or other scripting language PHP like SSI, a scripting language which is embedded in an HTML page. Microsoft’s ASP (Active Server Pages ) J2EE JSP for page scripting Java + class library Multiple runtime vendors Tomcat, BEA .NET is the latest technology from MS. range languages (VB.NET, C#, , C++, Cobol... ) compiled to a common intermediate code (MSIL) Extensive class library ASP.NET scripting page scripting

11 3-tier Issues Advantages: Challenges: Re-use of appropriate software
Software can be located on different machines for convenience and performance Resolves one-many relationships – many clients – one application, many applications – one database Challenges: well-defined, standardised interfaces between layers required. Software must be built to conform to interface standards The designer has to decide where to locate specific functions

12 Communication The ‘glue’ in this architecture is communication between software in the layers A single request from a user results in a complex flurry of communications and executions The flurry is composed of hundreds of simple interactions Sequence diagrams can be useful to provide a simplified description

13 Sequence diagram of SMS bus times request

14 Other layered architectures
ANSI/SPARC Database model The external or user level, characterised by Views The Conceptual level, comprising the full corporate data model at a logical level The Physical level, where data is stored in files

15 Channels between Layers
Layered communications model (Tanenbaum) Application Layer Transport Layer Network Layer Data Link Layer Physical Layer Presentation <> Middleware HTTP (The protocol which supports GET and POST messages) carrying a limited number of types of content (MIME types) Middleware <> Data stores ODBC with SQL request and table returns (whole table or row at a time)

16 SMS straw poll A simple application to tally votes on an issue.
A simple database to hold details of candidates and votes. Votes are texted into the server from a mobile phone, and are processed by cast.php At any time, the current status of the poll can be displayed using tally.php

17 Casting a vote

18 The simple database

19 The generated SQL CREATE TABLE tcandidate( candid CHAR(1) NOT NULL,
candname VARCHAR(40) NOT NULL, CONSTRAINT pk_tcandidate PRIMARY KEY (candid) ) TYPE=INNODB; CREATE TABLE tvoter( voteid CHAR(10) NOT NULL, CONSTRAINT pk_tvoter PRIMARY KEY (voteid) ALTER TABLE tvoter ADD INDEX (candid), ADD CONSTRAINT fk1_tvoter_to_tcandidate FOREIGN KEY(candid) REFERENCES tcandidate(candid) ON DELETE RESTRICT ON UPDATE RESTRICT;

20 Initialising the database
delete from tcandidate; insert into tcandidate values('B', 'George Bush'); insert into tcandidate values('K', 'John Kenney');

21 The cast script (simplified)
<?php /* input text the vote from the originating mobile number */ // map text to candidate id $query = "select * from tcandidate where '$text' = candid"; $dbresult = mysql_db_query($db,$query,$dblink); $cand = mysql_fetch_object($dbresult); $cid = $cand->candid; // insert the vote for this mobile $query = "insert into tvote values('$from', '$cid')"; print "Reply: you cast your vote for $cand->candname"; ?>

22 The tally script (simplified)
<?php // get the total number of votes cast $query = "select count(*) as total from tvote"; $dbresult = mysql_db_query($db,$query,$dblink); $total_tally = mysql_fetch_object($dbresult); $total = $total_tally->total; // get the total for each candidate $query = "select *, count(*) as tally from tvote natural join tcandidate group by tcandidate.candid"; //generate the results table while($cand = mysql_fetch_object($dbresult)) { $tally = $cand->tally; $tpc= round(( $tally/ $total ) * 100,2); $tpcr = round($tpc,0); print "$cand->candname has $tpc % <br/>"; } print "$total votes cast"; ?>

23 Exam application Input is a spreadsheet
Design a suitable normalised data model


Download ppt "3-tier application architecture A technical view"

Similar presentations


Ads by Google