Skip to content

Socket.io change feed help (performance)  #1230

Open

Description

@luke-robertson

Hello, im setting up a change feed that pushes to a socket io connection.

Im worried that setting up a new change feed for each io connection is gonna be a bit intensive.

Can rethink handle 100-1000 change feeds OK ?

Ill post my code below and any advice or feedback would be amazing, this is my first time using change feeds.

Also so i need to 'unsubscribe' from the change feed ?

Here is my current code :

    startSocket() {
        this.io.sockets.on('connection', socket => {
            console.log(' %s sockets connected', this.io.engine.clientsCount)

            socket.on('new_connection', target => {
                rethink
                    .table(target)
                    .changes({ includeInitial: true })
                    .run((err, cursor) => {
                        cursor.each((err, item) => {
                            socket.emit(target, item.new_val)
                        })
                    })
            })

            socket.on('disconnect', function() {
                console.log('disconnect: ', socket.id)
            })
        })
    }

Thanks
Luke

Activity

  1. Samhamsam commented on Mar 30, 2020

    @Samhamsam

    Same problem here. How did you solve it?

  2. SamLebarbare commented on Apr 21, 2020

    @SamLebarbare
    Contributor

    Handle changes state in a store, mutate the store when a change occur,
    new socket connection must get store state, sub to store changes.
    redux pattern is ideal for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions