Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Distributed Master-Worker Job Scheduling System

Overview

This project is a Java-based multi-threaded, distributed application that demonstrates client-server communication, concurrent task delegation, and load balancing.

The system consists of three main components:

  • Master node
  • Multiple Client nodes
  • Multiple Slave (Worker) nodes

Clients submit jobs (Type A or Type B) to the Master, which intelligently schedules and distributes them to connected Slaves based on current queue loads and optimal processing times.

Once a Slave completes a job, the Master is notified and sends the confirmation back to the original Client.


System Architecture

1. Master (Master.java & MasterLogic.java)

The central coordinator of the system.

It runs two ServerSocket listeners simultaneously:

  • Client Port (12486) – Listens for incoming client connections and job requests.
  • Slave Port (12487) – Listens for connecting worker nodes.

Threading & Load Balancing (MasterLogic.java)

The Master uses extensive multi-threading:

  • Listener threads
  • Reader threads
  • Writer threads

These exist for both clients and slaves, allowing the system to remain:

  • Event-driven
  • Non-blocking

Incoming jobs are passed to a Load Balancer, which calculates the projected completion time for each slave queue.

Processing times:

  • Optimal jobs: 2 seconds
  • Non-optimal jobs: 10 seconds

The Master routes each job to the Slave with the lowest projected completion time.


2. Slave / Worker (Slave.java)

Worker nodes process jobs assigned by the Master.

Slave Types

Slave A

  • Optimized for Type A jobs
  • Completes in 2 seconds
  • Processes Type B jobs sub-optimally (10 seconds)

Slave B

  • Optimized for Type B jobs
  • Completes in 2 seconds
  • Processes Type A jobs sub-optimally (10 seconds)

3. Client (Client.java)

End-user nodes that connect to the Master.

Clients:

  • Provide an interactive terminal interface
  • Submit jobs (Type A or Type B)
  • Asynchronously listen for JOB_COMPLETE messages from the Master.

Prerequisites

  • Java Development Kit (JDK) — Version 8 or higher
  • A terminal / command-line interface

How to Run

1. Compile the Source Code

Navigate to the src directory containing the os_term_project package and compile all .java files:

javac os_term_project/*.java

2. Start the Master

The Master must be started first so that clients and slaves have a server to connect to.

java os_term_project.Master

Note:
The master will output logs indicating it is listening on:

  • Port 12486 (Clients)
  • Port 12487 (Slaves)

3. Start the Slaves

Open new terminal windows for each Slave.

You must specify:

  • Slave Type (A or B)
  • Hostname
  • Port (12487)

Start Slave A

java os_term_project.Slave A localhost 12487

Start Slave B

java os_term_project.Slave B localhost 12487

4. Start the Clients

Open a new terminal window to act as a Client.

You must specify:

  • Client identifier
  • Hostname
  • Port (12486)
java os_term_project.Client A localhost 12486

You can run multiple clients concurrently in separate terminals.


5. Submit Jobs

In the Client terminal, you will see:

Please enter a message to send to the Master:
What job would you like to do? Job A or Job B.
Type A or B to send a job to the Master.
Or type -1 to exit.

Usage

  • Type A → Submit Job A
  • Type B → Submit Job B
  • Type -1 → Disconnect the client

System Execution Flow

  1. The Client sends a job request.
  2. The Master calculates optimal scheduling using load balancing.
  3. The Slave simulates processing:
    • 2 seconds (optimal)
    • 10 seconds (non-optimal)
  4. The Master receives completion confirmation.
  5. The Client receives:
Received confirmation message from Master: JOB_COMPLETE:<id>

Technical Highlights

Socket Programming

Implements robust TCP/IP communication using:

  • PrintWriter
  • BufferedReader

Concurrency & Synchronization

Handles shared resources safely using:

  • synchronized blocks
  • wait()
  • notifyAll()

This prevents race conditions in job queues.


Asynchronous I/O

Each network connection has dedicated Reader and Writer threads, ensuring:

  • No blocking on user input
  • No blocking on network streams
  • No deadlocks

This keeps the system fully asynchronous and responsive.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages