Client/Server Model

In the client/server model work is divided between clients, which request services (user interface, application logic), and servers, which provide services (data storage, processing). They communicate over a network, usually with SQL or remote procedure calls through standards such as ODBC and JDBC.

Architectures

  • Two-tier: the client application talks directly to the database server. It is simple, but business logic sits in every client, scaling is limited and each client holds a database connection.
  • Three-tier: a presentation tier (browser), an application (middle) tier with the business logic and a database tier. It scales better, is easier to maintain and secures the database from direct access.
  • Multi-tier (n-tier): extra tiers such as web server, cache and services.
  • Thin client carries little logic; fat (thick) client carries much.

Server Architectures

  • Transaction server (query server): clients send SQL or transactions and the server returns results.
  • Data server: sends data items (pages or objects) to the client, which does the processing; used by OODBMS, with client caching and locking protocols.
  • Server processes: a single-process server with one thread cannot use several CPUs; a process per client is heavy; a multi-threaded server shares memory and handles many clients with a pool of worker threads; a multi-server design uses several processes with a shared buffer pool and lock table.
  • Connection pooling and a dispatcher reduce the cost of making connections.

Performance

The load on a server behaves like a queue. With arrival rate λ and service rate μ the utilisation is ρ = λ / μ and, for a single server, the average response time is 1 / (μ - λ). Response time grows very fast when ρ approaches 1.

Definition: Three-tier architecture. A client/server design with a presentation tier, an application tier holding business logic and a database tier holding the data.

Table 2.4: Two-tier and three-tier architecture

Point Two-tier Three-tier
Business logic In the client In the middle tier
Scalability Low High
Security Database exposed to clients Database hidden
Maintenance Update every client Update the server

Example 2.4: Response time of a server

Problem: A database server needs 20 ms to serve a request, and requests arrive at 40 per second. Find the utilisation and the average response time. What happens if a second worker thread doubles the service rate?

Solution:

  1. Service rate μ = 1 / 0.020 = 50 requests per second.
  2. Utilisation ρ = 40 / 50 = 0.8.
  3. Response time = 1 / (μ - λ) = 1 / (50 - 40) = 0.1 s = 100 ms.
  4. With μ = 100: ρ = 0.4 and response time = 1 / (100 - 40) = 0.0167 s = 16.7 ms.

Result: One worker gives 80 percent utilisation and 100 ms; doubling the capacity gives 40 percent and 16.7 ms.

lam = 40
for workers in (1, 2):
    mu = 50 * workers
    rho = lam / mu
    resp = 1 / (mu - lam)
    print(f"{workers} worker(s): mu={mu}  utilisation={rho:.0%}  "
          f"response={resp * 1000:.1f} ms")
for lam2 in (40, 45, 49):
    print(f"lambda={lam2}: response={1000 / (50 - lam2):.0f} ms")

Output

1 worker(s): mu=50  utilisation=80%  response=100.0 ms
2 worker(s): mu=100  utilisation=40%  response=16.7 ms
lambda=40: response=100 ms
lambda=45: response=200 ms
lambda=49: response=1000 ms

Common mistakes

  • Placing all business logic in the client of a large system.
  • Letting clients connect directly to the database across the internet.
  • Running a server near 100 percent utilisation, where response time explodes.
  • Creating a new process for every request instead of pooling threads.

Key takeaways

  • Client requests; server serves; ODBC and JDBC connect them.
  • Two-tier, three-tier and n-tier differ in where the logic lies.
  • Data servers ship pages or objects; transaction servers ship results.
  • Multi-threaded servers with connection pools scale better.

Practice questions

  1. What are the three tiers?
  2. What does a data server send to the client?
  3. Why use a connection pool?

Answers to the practice questions

  1. Presentation, application (business logic) and database tier.
  2. Data items such as pages or objects.
  3. To avoid the cost of opening a new connection for every request.

Sources

  • Official BCA syllabus Advanced Database Systems, course code 25BCA406DS04, Unit II