The python DDS is too slow!

8 posts / 0 new
Last post
Offline
Last seen: 2 days 16 hours ago
Joined: 11/17/2022
Posts: 4
The python DDS is too slow!
my code is follow:
from common.ronovo_topic import *
from common.TopicName import *
import time
from asyncio.coroutines import iscoroutinefunction
def cost_time(func):
   def fun(*args, **kwargs):
   t = time.perf_counter()
    result = func(*args, **kwargs)
   print(f'func {func.__name__} cost time:{time.perf_counter() - t:.8f} s')
  return result

 

async def func_async(*args, **kwargs):
  t = time.perf_counter()
  result = await func(*args, **kwargs)
   print(f'func {func.__name__} cost time:{time.perf_counter() - t:.8f} s')
   return result

 

    if iscoroutinefunction(func):
       return func_async
    else:
      return fun
class DataReaderListenerImpl(dds.NoOpDataReaderListener):
   @cost_time
   def on_data_available(self,t_reader:dds.DataReader):
       t_reader.take()
       pass
participant = dds.DomainParticipant(domain_id=0)
topic = dds.Topic(
participant,TopicNames.PatientAct[0], TPC_PatientAct)
reader = dds.DataReader(dds.Subscriber(participant), topic)
# readerImpl = dds.DataReader(t_subscriber, dds.Topic(t_topic), t_qos)
# reader = RtiDataReader(readerImpl, t_cb)
listener = DataReaderListenerImpl()
reader.set_listener(listener,dds.StatusMask.ALL)
@cost_time
def take(reader):
# reader.take()
# print(a)
   pass
while True:
  time.sleep(0.001)
          take(reader=reader)
the result of print:
func on_data_available cost time:0.00054845 s
func take cost time:0.00000328 s
func on_data_available cost time:0.00048014 s
func take cost time:0.00000279 s
func on_data_available cost time:0.00035045 s
func take cost time:0.00000237 s
 
i hope the cost time is under 0.01ms for one topic. But it cost 0.4ms for instance one topic.
how to do if i want Increase the rate?
 
Offline
Last seen: 2 weeks 2 days ago
Joined: 04/02/2013
Posts: 182

Can you share the definition of TPC_PatientAct?

Offline
Last seen: 2 days 16 hours ago
Joined: 11/17/2022
Posts: 4
struct TPC_PatientAct {
T_Common common;
unsigned long long error;
T_custemOpState opState;
T_custemState state;
T_me rcmPospoint;
T_st rcmvpoint;
T_st rcmapoint;
T_h rcmfpoint;
double liftAnglePospoint;
double liftAnglevpoint;
double liftAngleapoint;
double liftAnglefpoint;
T_me custemPospoint;
T_st cvpoint;
T_t capoint;
T_h cfpoint;
double joPospoint[T_custem_JNT_NUM];
double jovpoint[T_custem_JNT_NUM];
double joapoint[T_custem_JNT_NUM];
double jofpoint[T_custem_JNT_NUM];
double aPospoint;
double avpoint;
double aapoint;
double afpoint;
double tensionPospoint;
double tensionvpoint;
double tensionapoint;
double tensionfpoint;
double srPospoint;
double srvpoint;
double srapoint;
double srfpoint;
double dogPospoint[T_custem_DOG_NUM];
double dogvpoint[T_custem_DOG_NUM];
double dogapoint[T_custem_DOG_NUM];
double dogfpoint[T_custem_DOG_NUM];
long dPospoint[T_custem_DRV_NUM];
long dvpoint[T_custem_DRV_NUM];
long dapoint[T_custem_DRV_NUM];
double dfpoint[T_custem_DRV_NUM];
double dTemppoint[T_custem_DRV_NUM];
boolean d;
boolean c;
double a;
double v;
char instrName[T_INSTR_NAME_LEN];
T_e e;
T_c c_1;
T_TType tType;
boolean isCd;
boolean isCt;
boolean isal;
};
Howard's picture
Offline
Last seen: 2 days 6 hours ago
Joined: 11/29/2012
Posts: 446

What are the sizes of the arrays used in the data structure?  i.e., what are the values of T_custem_JNT_NUM, T_custem_DOG_NUM, T_custem_DRV_NUM, T_INSTR_NAME_LEN?

 

Offline
Last seen: 2 days 16 hours ago
Joined: 11/17/2022
Posts: 4

The totoal size is 1472.

Howard's picture
Offline
Last seen: 2 days 6 hours ago
Joined: 11/29/2012
Posts: 446

I'm not sure what you mean by "total size".  Is that the size of each of the arrays defined in the data type?

If so, your performance may be limited by the performance of our Connext DDS Python API with respect to data types with array or sequence members.  We're working on improving the preformance for those data types.  But at this time, your performance may be as good as it gets.

Offline
Last seen: 2 days 16 hours ago
Joined: 11/17/2022
Posts: 4

Sorrry for that i cannot descrip clearly. My mean is that the size of TPC_PatientAct is 1472. As follow:

cout<<sizeof(TPC_PatientAct)<<endl; it will print 1472.

 

 

Howard's picture
Offline
Last seen: 2 days 6 hours ago
Joined: 11/29/2012
Posts: 446

Total size isn't the issue.  It's the number of elements in a structure.  Again, what are the values of T_custem_JNT_NUM, T_custem_DOG_NUM, T_custem_DRV_NUM, T_INSTR_NAME_LEN?