Code Monkey home page Code Monkey logo

Comments (11)

lucasvfventura avatar lucasvfventura commented on May 31, 2024 3

@alexellis My team is using GraphQL and we use subscriptions to push events to the UI that were triggered by other users. Subscriptions use Websocket behind the scene. This is the only point keeping us to move to a completely serverless solution.

Serverless.com with AWS supports it with the "new" API Gateway websockets api, but it isn't available yet in my GraphQL framework integration with the serverless framework.

from of-watchdog.

colearendt avatar colearendt commented on May 31, 2024 1

Just want to add some context here. In addition to streaming applications, there are a handful of app development frameworks in the data science ecosystem (Shiny, Streamlit, etc.) that depend heavily on websockets. The other place I have seen applications are in TTYs (terminal-emulators) and other heavily responsive / stateful applications.

With regard to how to set timeouts, I have seen many transparent proxies use something like "proxy read timeout" or "proxy write timeout.". In traefik (written in Go), idleTimeout seems to be the operative target.

In any case, websockets or other keep-alive connections seem to be handled independently of other types of requests.

The behavior that I experienced with fwatchdog not handling websockets definitely surprised me and took a while to debug - it just holds the socket open and doesn't return the data until the backend connection dies or fwatchdog's shutdown sequence is initiated. tcpdump on the container (which showed my function returning data from 8082->8080, and data never getting returned from 8080) was what finally led me to this thread.

(FWIW I'm not sure if this is the right GitHub repo or if I am using the "classic" watchdog, but this seemed like the newer target for feature discussions!). If I find someone willing to finance or if I find time to mock up a PR, I will let you know 😄

from of-watchdog.

alexellis avatar alexellis commented on May 31, 2024

Not right now since we'd have no way of giving QoS i.e. timeouts etc.

What is the usecase for a websocket to a function? How would you see timeouts working with this?

Alex

from of-watchdog.

rosko avatar rosko commented on May 31, 2024

We can consider a websocket server as a set of event handlers: connection, disconnect, message. In this case, it seems possible to be implemented using functions. And timeouts can work with that concept similarly as with regular serverless functions. Does it make sense?

from of-watchdog.

alexellis avatar alexellis commented on May 31, 2024

Websockets are inherently stateful with long running connections. How do you implement a timeout for an operation?

Maybe you could start with giving us a usecase in as much detail as you're comfortable with and we can try to explore the idea from there?

from of-watchdog.

rosko avatar rosko commented on May 31, 2024

I think it's better for me to explain using node8-express-template as an example. (https://github.com/openfaas-incubator/node8-express-template)

This template contains:

  • index.js - express.js initialization
  • function/handler.js - route handler

In the case of WebSocket, there will be a similar structure: one main script that initializes websocket server and one or many handlers.

index.js

const WebSocket = require('ws');
const connectionHandler = require('./function/connection.js');
const messageHandler = require('./function/message.js');
const disconnectHandler = require('./function/disconnect.js');

const wss = new WebSocket.Server({ port: 8080 });

wss.on('connection', function connection(ws, req) {
  connectionHandler(wss, ws, req);
  ws.on('message', function (message) {
    messageHandler(wss, ws, req, message);
  });
  ws.on('disconnect', function() {
    disconnectHandler(wss, ws, req);
  });
});

function/message.js

module.exports = (wss, ws, req, message) => {
  // Broadcast to everyone else.
  wss.clients.forEach(function each(client) {
    if (client !== ws && client.readyState === WebSocket.OPEN) {
      client.send(data);
    }
  });
}

So, we can measure timeouts for every websocket event – how much time it takes to handle the event using handler. Makes sense? Or I'm too naive and missing something? :)

from of-watchdog.

rosko avatar rosko commented on May 31, 2024

@alexellis WDUT?

from of-watchdog.

rvanzon avatar rvanzon commented on May 31, 2024

@rosko hi, I have the same question actually. Did you ever tried this out?

from of-watchdog.

rosko avatar rosko commented on May 31, 2024

@rvanzon not yet :)

from of-watchdog.

matti avatar matti commented on May 31, 2024

my usecase: run https://github.com/ws-doom

from of-watchdog.

alexellis avatar alexellis commented on May 31, 2024

I'm going to close this issue as it's already been answered.

We may consider websocket support in the future, however we've had no requests from commercial users for this as of yet. Ideally, we'd be looking for one of them to sponsor the work and maintenance of the feature. It would also break any timeouts and limits that people expect from FaaS platforms like OpenFaaS and Cloud Run.

from of-watchdog.

Related Issues (20)

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.