Code Monkey home page Code Monkey logo

Comments (5)

olahol avatar olahol commented on May 22, 2024

You are right, the reason this was done was because I did not wan't to block the hub if the Session.output channel was full.

I have to think about how to ensure that messages are read/written in order as I also notice that
there might be problems with this piece of code:

        if t == websocket.TextMessage {
            go messageHandler(s, message)
        }

Thank you for bringing it up 👍

from melody.

FZambia avatar FZambia commented on May 22, 2024

As I am developing https://github.com/centrifugal/centrifugo similar in many aspects I also have the same task:

sending to client: https://github.com/centrifugal/centrifugo/blob/master/libcentrifugo/hubs.go#L300

client's send method implementation: https://github.com/centrifugal/centrifugo/blob/master/libcentrifugo/client.go#L177

So Centrifugo uses separate unlimited size queue for every client. At first stages I used buffered channel with size 256 by default and closed client's connection when that buffer was full and sending into channel blocked. But it behaved bad in case of high message rate as client was disconnected just because it received more than 256 messages at one moment. Now with queue there is a little overhead but predictable behaviour.

I have another problem with dealing with slow clients (lots of allocations in code as I don't have access to SetWriteDeadline method at moment - I use SockJS not just Websockets - but hopefully will be able to improve this in near future). But this is not a problem for Melody as you already use SetWriteDeadline.

So this is one of possible solutions. Maybe you find a better one.

from melody.

olahol avatar olahol commented on May 22, 2024

Nice, the Centrifugo project looks really cool.

The queue solutions looks like it should work well for Melody, I'll have to take a closer look at it after work.

Thank you for the help!

from melody.

olahol avatar olahol commented on May 22, 2024

Thank you for your help @FZambia, as you can see in my code I took a different route than the infinite queue, instead I decided to dispatch the error handler and if the users wishes they can just increase MessageBufferSize.

from melody.

FZambia avatar FZambia commented on May 22, 2024

Great! Thanks for your responsiveness:)

from melody.

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.