Archived

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

How to get number of received bytes

Dear all,

how can I get the number of bytes received by a subscribing client?
I slightly modified the IceStorm cpp Clock example, so that I have this code for the subscriber client:
class EventMessageI : public EventMessage {
  public:
    virtual void report(const Event& evt,const Ice::Current&);
};

void EventMessageI::report(const Event& evt,const Ice::Current&) {

  //Get access to Event structure info
  //...

  //Get number of received bytes effectively sent by Ice
  //??
}

where Event is a struct in my .ice model, containing also maps/vectors and EventMessage is the defined interface. In the manual something related to this aspect is mentioned in the Message Header paragraph (pag. 1516, messageSize field in HeaderData" struct).
Another question uncorrelated to the previous is: is the "report" method executed in a different thread with respect to the main client thread?
I'm a novice with ICE so I'm sure that this is a trivial question or I'm missing something.
I thank you all in advance for your help,

Simone

PS: I'm using ICE version 3.5.1

Comments

  • benoit
    benoit Rennes, France
    Hi Simone,

    Welcome to our forums and Ice.

    The report method will be dispatched from the Ice server thread pool not from the main thread. If you want to dispatch it on the main thread, you will need to implement an Ice dispatcher (see Dispatching Invocations to User Threads for more information).

    Otherwise, there's no way to directly obtain the size of the message from the report() dispatch. You can however monitor the dispatched operations and get their size using Ice metrics (see The Metrics facet).

    To try out metrics, you can use the Ice hello demo and the Python metrics demo, for example:
    #
    # Start the C++ hello server with the administrative interface enabled and with the client invoke sayHello few times.
    #
    $ cd Ice-3.5.1-demos/demo/Ice/hello
    $ ./server --Ice.Admin.Endpoints="tcp -p 10004"
    $ ./client
    
    #
    # Collect the server metrics using the script from the python metrics demo.
    #
    $ cd Ice-3.5.1-demos/demopy/Ice/metrics
    $ ./Metrics.py --Endpoints="tcp -p 10004 -h localhost" --InstanceName="server" dump
    

    This should print out the dispatched invocation on the hello server along with the size of each request:
     +========================================+===+=====+=====+=====+========+
     |Dispatch                                |  #|Total|   Sz|RepSz|Avg (ms)|
     +========================================+===+=====+=====+=====+========+
     |hello [ice_isA]                         |  0|    2|   76|   16|   0.043|
     |hello [sayHello]                        |  0|   12|  348|   84|   0.047|
    

    Cheers,
    Benoit.
  • Many thanks for reply. I will follow your suggestions.
    In the meanwhile, browsing the forum, I found also the Stats approach. As suggested, I defined a MyStats class derived from Ice::Stats, added a method to retrieve the current or the accumulated bytes exchanged and set it in the communicator initialization data. At this point I manage to see the stream of bytes passed. Then within the report() method I'm doing this stuff to get access to Stats information:
    void EventMessageI::report(const Event& evt,const Ice::Current& current) {
    
      Ice::ObjectAdapterPtr adapter= current.adapter;
      Ice::CommunicatorPtr comm= adapter->getCommunicator();
      Ice::StatsPtr stats= comm->getStats();
    
      //at this point how to convert or cast StatsPtr to MyStat class, so that I can call its methods?
      //?
    
    

    By the way, I will also try your approach. What I would like to do at the very end is:

    - getting events in the client (done)
    - access to event information and transmission information (like nbytes, publisher, endpoint, ...)
    - pass this event to some handler method in the client main thread or some other user defined thread

    I will look deeper in the documentation and example to understand more. I thank you again for your support.

    Regards,

    Simone