Giter VIP home page Giter VIP logo

file-server-go's Introduction

Overview

A small learning exercise by writing a basic file server in Go

UPDATE: Basic frontend using sveltekit was added recently (check the frontend section)

Build backend only

docker build -t file-server-go .

Run backend only

docker run --memory="64m" --memory-swap="100m" -p 37899:37899 file-server-go

Observations around memory:
  • Running the free -h command from within the container will show incorrect results (see this answer)

    For instance, with the memory flag set to 64M and the swap flag set to 100M (effective swap is 100 - 64 = 36M);

    free -h (from inside container):

                  total        used        free      shared  buff/cache   available
    Mem:           2.9G        1.4G      259.6M       29.4M        1.2G        1.1G
    Swap:        512.0M      200.0M      312.0M
    

    docker inspect <container-id> (from the host, i.e. outside the container)

    CONTAINER ID   NAME               CPU %     MEM USAGE / LIMIT   MEM %     NET I/O       BLOCK I/O        PIDS
    8300bf4be0ba   quizzical_panini   0.00%     1.465MiB / 64MiB    2.29%     1.09kB / 0B   266kB / 12.3kB   7
    
  • Prior to using io.copy (and reading the entire file in memory) would result in an OOM if the file size is > 64MB

...
Containers:
  file-server-instance:
    Container ID:   containerd://bf13bd5b2e61eeae85b6c7a4f138dd1f66c525c2a78ca22cd2415bb373349c92
    Image:          file-server-go:0.0.1
    Image ID:       docker.io/library/import-2024-01-13@sha256:26ba3255996d8630e54fbca83d0f4b128bd12fae4039ddbd810089cd66e26507
    Port:           37899/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Sat, 13 Jan 2024 11:56:49 -0800
    Last State:     Terminated
      Reason:       OOMKilled
      Exit Code:    137
      Started:      Sat, 13 Jan 2024 11:56:34 -0800
      Finished:     Sat, 13 Jan 2024 11:56:49 -0800
    Ready:          True
    Restart Count:  1
    Limits:
apiVersion: apps/v1
      cpu:     1
      memory:  64M
    Requests:
      cpu:        700m
      memory:     64M
    Environment:  <none>

Build Frontend+Backend and deploy on local K8s! (Kind cluster)

Install kind

brew install kind

Create a cluster

kind create cluster --name playground --config infra/kind-cluster.yaml

Create deployment

k create -f infra/file-server.yaml

Delete deployment

k delete -f infra/file-server.yaml

Teardown cluster

kind delete cluster --name playground

Notes:

  • Each time you delete the cluster, run make kindload-<component> again. Because the images on the cluster don't persist

Voila!

Open your browser and visit http://localhost:5173/ alt text

List files flow

alt text

Download flow

alt text

Upload flow

alt text

file-server-go's People

Contributors

parthrs 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.