Subscriber dropping samples (can't keep up ?)

1 post / 0 new
Offline
Last seen: 8 years 2 months ago
Joined: 09/14/2016
Posts: 1
Subscriber dropping samples (can't keep up ?)

I have a publisher/subscriber pair (created using  DDSTheParticipantFactory->create_participant_from_config). The subscriber uses a dynamic reader and waits on DDS_DATA_AVAILABLE_STATUS to receive new data from the publisher. At publication rates of > around 5 Hz, the subscriber begins to "miss" new samples, getting worse as the publication rate is increased. It will typically go for 1 - 3 seconds without seeing new samples, then receive a short burst (2 - 10) of consecutive samples, and repeat this cycle. rtiddsspy sees all the data from the publisher so the problem appears to be in the subscriber. Here is the relevant subscriber code:

 

//
// Common method which does the work of creating the subscriber
//
void
CFAI_DDSSubscriber::makeSubscriber(const char *participantLibrary,
                                   const char *participantName,
                                   const char *subscriberName,
                                   const char *readerName)
{
  char *tmp;
   asprintf(&tmp, "%s::%s", participantLibrary, participantName);

  participant = DDSTheParticipantFactory->create_participant_from_config(tmp);
  if (participant == NULL) {
    free(tmp);
    throw std::runtime_error("create_participant error");
  }

  free(tmp);
  asprintf(&tmp, "%s::%s", subscriberName, readerName);
  dynamicReader = DDSDynamicDataReader::narrow(participant->
                                               lookup_datareader_by_name(tmp));
  if (dynamicReader == NULL) {
    free(tmp);
    subscriberShutdown(participant);
    throw std::runtime_error("lookup_datawriter_by_name error");
  }
  free(tmp);

  //Set up the WaitSet and Condition, to wait for new data
  waitSet = new DDS::WaitSet();
  myStatusCond = dynamicReader->get_statuscondition();

  myStatusCond->set_enabled_statuses(DDS_DATA_AVAILABLE_STATUS);
  waitSet->attach_condition(myStatusCond);

  // Create dynamic data "container" to receive samples
  data = dynamicReader->create_data(DDS_DYNAMIC_DATA_PROPERTY_DEFAULT);

}

/**
   Wait for new data. These methods return a pointer to a DDS dynamic data
   object. The type/structure of this object is defined in the XML file.
 */

DDS_ReturnCode_t
CFAI_DDSSubscriber::waitSample(DDS_Long timeout_ns,
                                                DDS_DynamicData **sample)
{
 
  DDS_Duration_t timeout;
  DDSConditionSeq activeConds;
  DDS_ReturnCode_t retCode;
  DDS_SampleInfo sampleInfo;

  if (timeout_ns >= 0)
    timeout = DDS_Duration_t::from_nanos((DDS_UnsignedLong)timeout_ns);
  else
    timeout = DDS_Duration_t::from_seconds(DDS_DURATION_INFINITE_SEC);

  // Create a new container to receive the data
  DDS_DynamicData *data = dynamicReader->create_data(DDS_DYNAMIC_DATA_PROPERTY_DEFAULT);

  // Wait for new data
  retCode = waitSet->wait(activeConds, timeout);
  if (retCode == DDS_RETCODE_OK)   // data is available
    // Get the new data (single sample)

    retCode = dynamicReader->take_next_sample(*data, sampleInfo);

  *sample = data; // Return the dynamic data

  return(retCode);
}

Is there anything obviously wrong with this code which could cause it to misss new samples ?

I'm quite new to DDS and based the code on samples from the documentation. Any help or suggestions would be much appreciated.

Organization: