Git Product home page Git Product logo

headout-assignment's Introduction

HTTP Server Optimization Assignment

This repository contains the implementation of a simple HTTP server to fulfill the requirements outlined in the assignment.

Implementation Details

HTTP Server

The HTTP server is implemented using Express.js, a web application framework for Node.js.

  • The server listens for incoming GET requests on the /data endpoint.
  • It accepts two query parameters: n (file name) and m (line number).
  • If both n and m are provided, it returns the content of the file /tmp/data/n.txt at line number m.
  • If only n is provided, it returns the entire contents of the file /tmp/data/n.txt.

Random Text Files

Random text files with around 100MB of content each are generated using a separate script named create-files.js. These files are stored in the /tmp/data directory.

Dockerfile

A Dockerfile is included in the root project directory to build a Docker image of the HTTP server. The Dockerfile ensures the following requirements are met:

  • Compatible with both ARM architecture and x86.
  • Exposes port 8080.
  • Allocates a maximum of 1500 MB RAM and 2 CPU cores to the Docker container.

Usage

Prerequisites

  • Node.js installed on your system.
  • Docker installed on your system.

Running the Server Locally

  1. Clone this repository to your local machine.
  2. Install dependencies using npm install.
  3. Run the server using node server.js.
  4. Access the server at http://localhost:8080.

Building and Running Docker Image

  1. Make sure Docker is running on your system.
  2. Navigate to the root project directory.
  3. Build the Docker image using docker build -t http-server ..
  4. Run the Docker container using docker run -d --rm --name http-server -p 8080:8080 --memory 1500m --cpus 2 http-server:latest.

Additional Notes

  • The provided code is a basic implementation and may require further optimization and error handling based on specific requirements.
  • Ensure to create the necessary random text files in the /tmp/data directory before running the server or building the Docker image.
  • For further optimizations or improvements, consider implementing caching mechanisms, error handling for file operations, and performance tuning based on real-world usage scenarios.

headout-assignment's People

Contributors

nihal337 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.