Coder Social home page Coder Social logo

live_tcp's Introduction

LiveTcp

This is an experiment to monitor a TCP service that only exposes a request/response inteface without a durable socket connection. Any observed changes are broadcast over a Phoenix PubSub to allow LiveViews to subscribe to these changes.

Apps

This umbrella project contains two apps:

  • :live_tcp_monitor a simple Phoenix application that starts and consumes the monitors.
  • :live_tcp_server a simple TCP server to emulate a back-end. It also exposes an API through iex to change values.

Both applications are started when you run iex -S phx.server from the root folder.

TODO

  • Start a very simple embedded TCP server and add an interface to change values (from iex).
  • Dynamically start monitors.
  • Observe changes in a LiveView.
  • Persist monitor specifications to survive a system restart, and make sure all registered monitors are restarted at startup.
  • Use Ranch to implement the TCP server.
  • Do a performance benchmark with a few thousand monitors.

Development

You can use asdf and the provided .tool-versions to get the correct erlang and elixir environment.

Start up a postgres database with docker by running docker-compose up -d in the root folder. Stop the database by running docker-compose down --remove-orphans.

Alternatively you can use following commands to start and stop a postgres database, using only docker without docker-compose:

docker run --detach -e POSTGRES_PASSWORD="postgres" -p 5432:5432 --name live_tcp_db postgres
docker stop live_tcp_db && docker rm live_tcp_db

To start your Phoenix server:

  • Install dependencies with mix deps.get (in the root folder)
  • Create and migrate your database with mix ecto.setup (in the apps/live_tcp_monitor folder)
  • Start Phoenix endpoint with mix phx.server or inside IEx with iex -S mix phx.server (do this in the root folder to make sure both applications start)

Now you can visit localhost:4000 from your browser.

Use the application

To start a monitor with some identifier simply visit localhost:4000/monitors/1 (the last part inidicates the identifier).

To change a monitored value you need the iex console. Simply execute:

LiveTcp.Server.set_value("1", "new value")

The first arguement indicates the identifier (which you used to start the monitor above). The second argument is the new value for this identifier. This change should be observed within a few seconds, without reloading the LiveView.

live_tcp's People

Contributors

linusdm avatar

Stargazers

 avatar Daniel Blendea avatar

Watchers

James Cloos avatar  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.