ITCE320 - Ch6: Server Architecture and Multithreading

LikeIntegral avatar
LikeIntegral
·
·
Download

Start Quiz

Study Flashcards

10 Questions

What is the primary purpose of a server in a computer network?

To wait for client requests, respond to those requests, and then wait for more requests.

What are the key characteristics of a server in terms of its availability to clients?

Available, approachable, reliable, and scalable.

What is the difference between a single server and a server farm?

A single server is a single piece of hardware or software, while a server farm is a group of mirrored or cloud-based servers.

What is an example of a client and a server in a web-based scenario?

Firefox web browser as the client and Apache web server as the server.

How are requests generated in a client-server architecture?

Requests are generated by clients, either on the same host as the server or on a remote machine.

What is the purpose of common port numbers in server communication?

To allow clients to easily connect to common servers without manual configuration.

What is the role of the Internet Network in client-server communication?

It acts as a medium for clients to reach the server and send requests.

What is the main difference between a single-threaded server and a multithreaded server?

A single-threaded server handles one request at a time, while a multithreaded server can handle multiple requests concurrently.

What is the significance of socket programming in client-server communication?

It enables the creation of network sockets, allowing clients to connect to servers and exchange data.

What is the advantage of concurrent connections in a multithreaded server?

It enables the server to handle multiple requests simultaneously, improving performance and responsiveness.

Study Notes

Single-Thread Programs

  • A single-thread program is a script with statements and expressions executed in sequence
  • Easier to design and used in programs that handle single connection/session at a time
  • Vulnerable to denial-of-service attacks
  • Connect and keep the connection on, keeping the server blocked at recv() expression
  • Resend some data before the blockage timeout (if it is configured)

Behavior with Multiple Connections

  • When a client tries to connect to a single-threaded server that is in session with another client
  • The OS starts a three-way TCP handshake with the second client to set up a connection
  • The connection will be kept at OS’s listen queue until the ongoing conversation is concluded
  • Once the server code has looped back to its next call to accept(), the second client’s connection will be available to the server
  • Start exchanging requests and responses over that socket

Single-Threaded Server and CPU Utilization

  • Poor resources utilization
  • recv() causes blockage, and no other expressions are executed during blockage time
  • Until receive data from the client
  • Timeout

Single-Thread Server Example

  • Create a socket and bind it to the loopback address and port 22221
  • Listen for incoming connections
  • Accept a connection and receive client name
  • Start a chat loop to send and receive messages
  • Close the connection when the client sends "quit"

Multi-process and Multi-Thread Programs

  • Multiple lightweight flow of executions running at the same time
  • Multi-threading: technique that allows an execution of several tasks of one process at the same time
  • Single core: execution of different codes are all queued, no parallel processing for both single and multi-threaded scripts
  • Multiple cores: parallel executions at the same time

Multi-process vs Multi-threaded

  • Multi-process Programming: each process runs as a standalone program, allocated code and data memory for every process
  • Multi-threaded: multiple threads running in a single process, sharing code and data memory
  • Use join() method to block until a thread terminates

Returning Threads

  • The Main Thread: return the main Thread object
  • The Current Thread: return the current Thread object
  • Returning list of threads: use threading.enumerate() to get a list of active threads

Example: Wait for all Active Non-Main Threads

  • Get a list of active threads using threading.enumerate()
  • Iterate through the list and join each thread

Multithreaded Server

  • Create multiple threads to handle multiple client connections
  • Each thread handles a separate client connection
  • Use threading and socket libraries to create a multithreaded server

Background

  • The Internet is used to share services
  • Entities to provide services need to be available, approachable, reliable, and scalable
  • Connected by program entities to ask for services

Server

  • A server provides a service that is needed by one or more clients
  • Can be a single server or a server farm (mirrored/cloud)
  • Example: Apache web server responds to requests from Firefox as the web client

Reaching Services

  • Requests are generated by clients
  • Clients can be at the same host as the server or at a remote machine
  • Reaching the server mechanisms:
    • Common servers use well-known common port numbers
    • Not common servers need a mechanism to verify the server port number to the client

This quiz covers the basics of single-thread programs, including their characteristics, advantages, and limitations. It also touches on the vulnerability of single-threaded programs to denial-of-service attacks.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser