A double increase in nodes creation takes four times

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
ssmaung
Sr. Member
Sr. Member
Posts: 17
Joined: 09 Jun 2021, 11:42

A double increase in nodes creation takes four times

Post by ssmaung »

Hello,
I was trying [server_lesson03] from [UaSdkCppBundleSource\examples\server_gettingstarted] with C++ based OPC UA Client Server SDK (Bundle) v1.7.4.

----------------------------------------------------- Changes to Sample Code -------------------------------------------------------------------------------------------------

The following two modifications were made.

(1) Only use AIR_CONDITIONER type and did not use FURNACE type.
#define NUMBER_AIRCONDITIONER 100000
#define NUMBER_FURNACES 0

(2) Only two Variables (PowerConsumption) and (State) are added and the tree will be something like below.
> Root
>> Objects
>>> BuildingAutomation
>>>>> AirConditioner_1
>>>>>> PowerConsumption
>>>>>> State

-----------------------------------------------------Measure Performance -------------------------------------------------------------------------------------------------

Then I measured performance of creating the Controller Object Instances in [NmBuildingAutomation::afterStartUp()] method.

auto start = std::chrono::high_resolution_clock::now();

/**************************************************************
* Create the Controller Object Instances
**************************************************************/
for ( i=0; i<count; i++ )
{
ret = m_pCommIf->getControllerConfig(
i,
controllerType,
sControllerName,
controllerAddress);

if ( controllerType == BaCommunicationInterface::AIR_CONDITIONER )
{
xxxxxx
}
else
{
xxxx
}
}

auto finish = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = finish - start;
printf("\n Elapsed time for count %d is %f \n", count, elapsed.count());

-----------------------------------------------------Result -------------------------------------------------------------------------------------------------
#define NUMBER_AIRCONDITIONER 100000 ==> 10.90 seconds
#define NUMBER_AIRCONDITIONER 200000 ==> 40.00 seconds
#define NUMBER_AIRCONDITIONER 400000 ==> 160.23 seconds

-----------------------------------------------------Question-------------------------------------------------------------------------------------------------
Why doubling creation of number of nodes increases takes 4 times?

Thank you in advance.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3064
Joined: 18 Mar 2011, 15:09

Re: A double increase in nodes creation takes four times

Post by Support Team »

Hello,

Having so many nodes in one level is not a normal use case. An OPC UA Server is typically exposing a full mesh network of nodes or in most cases at least a tree of objects where there typically not more than 1000 child nodes below another node.

The increasing time is coming most likely from re-allocations of always the same reference list when you add 400.000 references to one node.
Best regards
Unified Automation Support Team

ssmaung
Sr. Member
Sr. Member
Posts: 17
Joined: 09 Jun 2021, 11:42

Re: A double increase in nodes creation takes four times

Post by ssmaung »

Thank you very much for prompt reply.
It is useful advice and I have realized it now that I have to re-consider the tree structure.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3064
Joined: 18 Mar 2011, 15:09

Re: A double increase in nodes creation takes four times

Post by Support Team »

Hello,

the NodeManagerUaNode (and also the NodeManagerBase derived from NodeManagerUaNode) usees a Hashtable to lookup nodes. The default size is set to 10007. If you add more nodes that will result in a lot of collisions and that again makes adding Nodes and lookup in the table slow. You should set the hashtable size to a number equal or bigger than the total number of nodes in that namespace. That will speedup all node lookup operations a lot.
Best regards
Unified Automation Support Team

ssmaung
Sr. Member
Sr. Member
Posts: 17
Joined: 09 Jun 2021, 11:42

Re: A double increase in nodes creation takes four times

Post by ssmaung »

Thank you for providing info about Hashtable size. After hashtable size is changed, it did really increase the performance.

ssmaung
Sr. Member
Sr. Member
Posts: 17
Joined: 09 Jun 2021, 11:42

Re: A double increase in nodes creation takes four times

Post by ssmaung »

Hello,

In NodeManagerUaNode constructure, nHashTableSize's preferred sizes are 1.009, 10.007, 100.003, 1.000.003, 10.000.019.
I understood that it is recommended.

Can we also choose any numbers depending on the number of nodes which my server can have?
If we choose any number other than preferred sizes, can there be any impact?

Thank you in advance.

Post Reply