Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket.io change feed help (performance) #1230

Open
luke-robertson opened this issue Jan 2, 2019 · 2 comments
Open

Socket.io change feed help (performance) #1230

luke-robertson opened this issue Jan 2, 2019 · 2 comments

Comments

@luke-robertson
Copy link

luke-robertson commented Jan 2, 2019

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

@Samhamsam
Copy link

Same problem here. How did you solve it?

@SamLebarbare
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants