Code Monkey home page Code Monkey logo

Comments (7)

l3nz avatar l3nz commented on June 18, 2024

Hello there,
this really sounds weird! can you reproduce the problem with a minimal test?
l.

from ari4java.

pablopelaezg avatar pablopelaezg commented on June 18, 2024

Hi Lenz,

Thanks for your reply. No, I can't. When I initially test my app based on your library, I executed 10 calls as maximum and anything works OK. Another member of my team try to test the app based on a stress scenario, and when the number of calls reach 100 calls that error is shown.

I suspect that the error could be due to the Netty Http Client, the pipeline handling is so confuse to me, and it could mess the streams. I'm creating a fork based on the apache http client to verify this. I will tell you my conclusion in the next days.

from ari4java.

l3nz avatar l3nz commented on June 18, 2024

Yes the Netty pipeline is a PITA. But it really sounds strange that things get mixed up....

from ari4java.

pablopelaezg avatar pablopelaezg commented on June 18, 2024

Hi Lenz,

I do the fork w/ Apache HTTP client, and works perfectly until 100 calls (I haven't tested with more calls, will do in the next hours). But, another problem that I detected is that the Actions that inherit from BaseAriAction will have serious syncronization problems, because the reset() method is called each time i need to execute a command over the ARI, and generates a nullpointerexception when another thread use it. I tried with the following two options:

  • Synchronize the Action that I'm using (duh), but it will be a bottleneck if you have many threads/calls.
  • Create an Action object each time I want to execute a command over the ARI, this should work nice but strangely it lets execute only 2 or 3 calls of 100. I don't have any idea why happens this.

I like to know your opinion about this scenario, and if you want some hand in development tasks I'm pleased to help you.

P.S. Your library is awesome!

from ari4java.

l3nz avatar l3nz commented on June 18, 2024

I am not sure I understand. Every time you want to run an action you run a different action, so there should be no synchronization issues. It is not meant to be reused.

from ari4java.

pablopelaezg avatar pablopelaezg commented on June 18, 2024

Hi Lenz, I tried to create a different "Action" object for each action to execute, but the result was unsuccessfull, only 3 calls of 100 was executed correctly. I assume that due to this you have in each Action a reset() method to use only one instance for action type (a kind of Singleton). I do several changes in the library, e.g. changing the websocket and http client, letting the Action as "static" classes, and another fixes, and the result was partly successfull in a stress test of 1000 calls / 50 concurrents. The error is mostly in the Asterisk, when the following error is showed several times: task processor queue reached 500 scheduled tasks, some Playbacks failed to play and so on.

from ari4java.

grahambrown11 avatar grahambrown11 commented on June 18, 2024

@Pablop992 I think your issue is you are re-using the object from ARI in multiple threads - that'll be a problem, you need a new object for each thread. The default EventLoop uses 2 times the CPUs reported by java (Runtime.getRuntime().availableProcessors()) override this by suppling the system property io.netty.eventLoopThreads. I set mine to 10 using -Dio.netty.eventLoopThreads=10 in the java command you can also use System.setProperty("io.netty.eventLoopThreads", "10"); in your code.
bad (re-using channels object):

ARI ari = ARIFactory.nettyHttp(...);
ExecutorService executor = Executors.newFixedThreadPool(10);
ActionChannels channels = ari.channels();
for (int i=0; i < 100; i++) {
    executor.execute(() -> {
        channels.originate(...);
    });
}

good (new channels object for each thread):

ARI ari = ARIFactory.nettyHttp(...);
ExecutorService executor = Executors.newFixedThreadPool(10);
for (int i=0; i < 100; i++) {
    executor.execute(() -> {
        ActionChannels channels = ari.channels();
        channels.originate(...);
    });
}

A suggestion on processing the ActionEvents is to create your own thread pool and schedule your application work in your own pool. I found that Asterisk doesn't send the next event until the previous one is complete. My onSuccess looks similar to this:

ExecutorService executor = Executors.newFixedThreadPool(10);
AriCallback<Message> callback = new AriCallback<Message>() {
            @Override
            public void onSuccess(Message message) {
                logger.debug("ARI onSuccess");
                executor.execute(() -> {
                    if (message instanceof StasisStart) {
                        handleStatisStart((StasisStart) message);
                    }
                });
            }
            @Override
            public void onFailure(RestException e) {
                logger.debug("ARI onFailure", e);
            }
};

from ari4java.

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.