Giter Site home page Giter Site logo

Comments (7)

FZambia avatar FZambia commented on May 14, 2024

When I wrote this I thought that this can prevent blocking when slow client does not read from socket fast enough. Your last solution will help with arbitrary throughput - but what if send blocks and m will grow more and more? I don't have strong understanding if this blocking possible or not.

from centrifugo.

klauspost avatar klauspost commented on May 14, 2024

client.send() blocking shouldn't be an issue, since sendMessages will always pull messages from c.messageChan.

But if c.sess.Send(msg) doesn't return, m will keep growing. What do you think would be the optimal solution? A 10 second (configurable) timeout on c.sess.Send(msg)?

from centrifugo.

FZambia avatar FZambia commented on May 14, 2024

For raw websocket connection there is SetWriteDeadline (godoc) method available, but SockJS session has no such possibility.

from centrifugo.

klauspost avatar klauspost commented on May 14, 2024

We could wrap message sending in a function:

func (c *client) sendTimeout(msg string) error {
  to := time.After(time.Second)
  sent := make(chan error)
  go func() {
      sent <- c.sess.Send(msg)
  }()
  select {
     case err := <- sent:
        return err
     case <- to:
        return ErrSendTimeout
  }
  panic("unreachable")
  return nil
}

The timeout length could be added to the client.

The thing that I don't really like about this solution is that we are spawning 2 goroutines to send a single message. Not a huge deal - goroutines are cheap, and it does seem like it is required.

I will make a PR proposal. It is a bit easier to discuss.

from centrifugo.

FZambia avatar FZambia commented on May 14, 2024

Maybe the best way right now - make buffer larger and make it configurable and see how it goes? And then after writing some benchmark tests it will be more clear what's the right solution to this?

from centrifugo.

klauspost avatar klauspost commented on May 14, 2024

I made a proposal in #23. After a few rewrites I think it is fairly unobtrusive, light on resources and rather easy to follow (except perhaps the ring queue implementation).

from centrifugo.

FZambia avatar FZambia commented on May 14, 2024

Looks very interesting! Not sure this line necessary as clean method must be called anyway. There is old benchmark for Centrifuge - will try to run it after work to see memory and performance impact of these changes.

from centrifugo.

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.