Coder Social home page Coder Social logo

Comments (13)

mrniko avatar mrniko commented on May 17, 2024

I would recommend you to use ack (acknowledgment of received data) https://github.com/mrniko/netty-socketio-demo/blob/master/server/src/main/java/com/corundumstudio/socketio/demo/AckChatLauncher.java
So you will send next message only then ack of recieved message sended by server to client. Because if you send it to server right after first message this leads to many waiting threads on server as a result, which will cause a performance degradation on server.

from netty-socketio.

ctpahhik avatar ctpahhik commented on May 17, 2024

Unfortunately it's not suitable for us as is. If processing takes 'long' time and acknowledge is sent before processing command we can meet this issue again, if ack is sent after processing we will have significant performance degradation as client will wait for each command to be processed which is not the requirement.
As for me, many threads should process messages simultaneously from different sessions, but messages from one session should be processed consequentially (with one or different threads).
In any case I have to add/use some mediator queue for commands either in my code or in your library. I'd prefer library.
If you are going to left such behavior as "feature" :) please give some advice where I could start to implement it within your lib.

from netty-socketio.

mrniko avatar mrniko commented on May 17, 2024

I'll add new option in Configuration class for this mode.

from netty-socketio.

ctpahhik avatar ctpahhik commented on May 17, 2024

Thank you very much!
Will look forward for it.

from netty-socketio.

mrniko avatar mrniko commented on May 17, 2024

But keep in mind, in case of using XHRPollingTransport like in your case or websockettransport if client don't get ping from server in certrain time interval it will drop connection. What do you think to fix this?

from netty-socketio.

ctpahhik avatar ctpahhik commented on May 17, 2024

It's a good question, but our 'long' is expected to be not so long to cause timeout...

Also, as socket.io has reconnection mechanism it may help us in critical cases (actually we never tested if it works for us :) and not sure that will be due to load balancing)
As for me, technical messages may be processed separately but there is few open questions. For example what to do if close session message is received? - close it immediately or wait while previous messages to be processed, etc.
Again, if processing became too long which means that server is overloaded, dropping some connections is not so bed solution, they will be rebalanced to less loaded one.

from netty-socketio.

mrniko avatar mrniko commented on May 17, 2024

Have you tried this simple trick in handler?:
synchronize(client) {
....
}

client instance will be always the same during session.

from netty-socketio.

ctpahhik avatar ctpahhik commented on May 17, 2024

Yes, I've added synchronization in code and it helps a lot.
We don't have simultaneous execution but as I understand commands reordering is still possible (can't check it for now), so it would be great if you implement feature in question.
In addition if there, for example, 10 clients with 10 commands from each and 5 worker threads there is possibility that all threads take commands from the same client and will be executed one by one, for this time there will be lack of threads for other clients.

from netty-socketio.

mrniko avatar mrniko commented on May 17, 2024

Take a look at this sample:

https://gist.github.com/4692912

I think it's right what you want!

from netty-socketio.

ctpahhik avatar ctpahhik commented on May 17, 2024

Thanks, it's something I've talked about at the beginning.
It solves thread starvation, but unfortunately doesn't prevent messages reordering :(

from netty-socketio.

mrniko avatar mrniko commented on May 17, 2024

It uses queue, so it should prevent messages reordering. Have you test it?

from netty-socketio.

ctpahhik avatar ctpahhik commented on May 17, 2024

Yes, messages will be processed in strict order, but they can be put in queue in wrong order the same way as before.
No I haven't tested it yet, will do when have time.
But as usual it's hard to test multi-threading code and it doesn't guarantee that it will work correctly on production. Especially on weird hardware like in our case.

from netty-socketio.

mrniko avatar mrniko commented on May 17, 2024

All messages processed in same order they came. And this https://gist.github.com/4692912 solution allows to queue handlers invocation in right order.

from netty-socketio.

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.