docs
docs copied to clipboard
Socket.io change feed help (performance)
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
Same problem here. How did you solve it?
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.