Archived

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

AMD data copying overhead

Situation: I have an AMD method which receives a data array (sequence<sequence<int>>) and adds this array to a job object which is queued for processing. The problem is that for some processing options, the copying of the data to a job object takes 80% of the total time (i.e. the actual data processing is the other 20%). For other processing options its only takes 5% of the total time (i.e. 95% data processing).

Question: Is there a way to avoid copying the data to the job object? In other words, is there a way to have the AMD method receive a smart pointer to the data array instead of a reference (I'm working in C++)?

The other option of course would be to not create any jobs, depending on the data processing configurations and do the data processing in the Ice server thread that handles the AMD call. But that would defeat the AMD purpose, at least for these calls. Another option would be to have an AMD method and a normal synchronous method, were it not for the fact that the caller doesn't know about data processing options.

Comments

  • mes
    mes California
    Hi,

    There are a couple of ways you could approach this, but neither are really ideal.

    First, you could implement a blobject servant by subclassing BlobjectArrayAsync. You'd receive a pair of pointers into the request buffer, and then you'd have to create an InputStream to manually unmarshal the operation parameters. The big disadvantage here is that the code can become complex and fragile; you'd have to remember to update this code any time the Slice definitions change.

    If you don't mind changing your Slice definitions, the simpler solution is to make your data array a member of a class and have the clients send a class instance containing the data. This way you could simply retain a reference to the class instance in your job queue and avoid any additional copies. Of course this means you're changing your "contract" to fix an implementation detail, which is best avoided when possible.

    Regards,
    Mark
  • I never used classes before so I assumed the servant method would get a reference and not a smart pointer to the class, which is the case for structures, sequences, etc (which makes me wonder why ...). But it doesn't, so great! I'm still testing different designs, so changing contracts is not a problem. Would passing a class which contains a sequence produce significant overhead compared to passing the sequence itself?
  • mes
    mes California
    Would passing a class which contains a sequence produce significant overhead compared to passing the sequence itself?
    Assuming you're using Ice 3.5, the additional overhead for the class instance will be minimal. You can further reduce it by using compact type IDs if you wish.

    Regards,
    Mark
  • Thanks for your help Mark!
    Cheers,
    Wout