Archived

This forum has been archived. Please start a new discussion on GitHub.

Questions regarding to AMI

I am trying to using AMI to asynchronous sending messages to the server and get replied back. First, I test sending one message and wait until getting replied back then I test sending batch of messages and waiting until batch messages back to send another group of messages. I expect the second test should have better performance than first test since the client don't need to wait for each message back, but the result make me surprised. The performance for them is quite the same so I get some print out in sending and callback method. I find most calls for the second one is quite like the first one, being synchronized.
Any comments and suggestions?

Comments

  • mes
    mes California
    Hi,

    If your server is single-threaded then it can only process one request at a time, which would cause the behavior you are seeing. Read the FAQs below and let us know if you are still having trouble:

    Why do I not get concurrent invocations in a server?

    Why do I not get concurrent replies to asynchronous invocations?

    Take care,
    Mark
  • Thanks, Mes.

    Thanks, but I do add the thread pool for the server. By the way, I am not sure the Ice.ThreadPool.Client.Size is set on the server sice or client side. My client is single threaded.
    Having a loop like below:
    for (int i = 0; i < 10; i++) {
    System.out.println("Message sending....");
    message.sendMessage_async(reply, wrapper);
    count++;
    }

    And in the server sendmessage method I set:
    Thread.sleep(5000) to make the callback delayed.

    I expect to see the client sending multiple messages to get one replied back since the object is blocked, but it seems the client is blocked to get reply back.
  • mes
    mes California
    Hi,

    It's difficult to say what the problem might be without more information. If you can post an archive containing the source code of a complete example (including configuration files), we can take a look at it. Please also specify the versions of your operating system, Ice, and compiler.

    Take care,
    Mark
  • Thanks, Mike. It will help me a lot. Is any place in the forum that I can attach my testing code? if not, could you send me your contact info to my email address: zaoliu@gmail.com? So I can sent you my testing code.

    Thanks,
    Zao
  • mes
    mes California
    You can attach a .ZIP file to messages here on the forum.

    Mark
  • I have attached the code to the message.
    ice.zip 34.3K
  • ICE Version: 3.2.1
    Compiler: java 1.5
    OS: Linux 2.6.16.46-0.12-smp
  • matthew
    matthew NL, Canada
    The problem is that you are reusing the same AMI response object over & over like so:
    api.AMI_message_sendMessage reply = new impl.AMI_message_sendMessageI(...);
    //...
    for (int i = 0; i < numbatched; i++) {
      message.sendMessage_async(reply, wrapper);
      addCount();
    }
    

    You must not do that as mentioned in the Ice manual (33.3.4):
    A callback object must not be used for multiple simultaneous invocations. An
    application that needs to aggregate information from multiple replies can
    create a separate object to which the callback objects delegate.

    If you alter your code so that you use a unique callback object per request then things will work as you expect.
  • Hi matthew,

    Thanks for your feedback. I thought my code is like sequential invocation not simultaneous invocation.

    Is this mean every message_async call should create a new callback object?
  • benoit
    benoit Rennes, France
    Hi,

    Yes, otherwise the AMI requests are serialized (the AMI request waits for the response of the previous request before being able to reuse the callback object).

    Cheers,
    Benoit.