Page 1 of 1

Multithreaded requests to OPC UA Server

Posted: 26 Aug 2013, 12:27
by gisTRON
I have a project with several subdirectories. Each subdirectory contains a machine.
- myProject
+ machine A
+ machine B
+ machine C

Every machine itself has several subdirectories. e.g.

- machine A
-- value1
-- value2
+value3..50

Right now I query everything sequentially.

query machineA(); takes 3 seconds
query machineB(); takes 3 seconds
query machineC(); takes 3 seconds
---------------------------------------------
takes 9 seconds to read all values for all 3 machines. I am not sure why it takes 3 seconds for each subdirectory.

Would the OPC UA Server be able to work with multithreaded requests and provide the data for 3 machines in 3 and not 9 seconds?
Is there any multithreading server-side or is everything done sequentially?

Re: Multithreaded requests to OPC UA Server

Posted: 27 Aug 2013, 08:18
by Support Team
Hi gisTRON!

What are you doing to access when you say ‘query machineA’. Is this a file I/O call using the .NET DirectoryInfo structure? If so performance is very dependent on the system and but 3s does sound large unless it is a recursive browse through a directory structure. In the .NET Server SDK there are two ways to process requests: one by one or as batches. If you use the ‘one by one’ design pattern then the requests are processed sequentially. You control which design pattern you use by the methods you choose to overload.
For example, the Read method signatures are:

Code: Select all

protected virtual DataValue Read(
    RequestContext context,
    NodeAttributeHandle nodeHandle,
    string indexRange,
    QualifiedName dataEncoding)

protected virtual void Read(
    RequestContext context,
    TransactionHandle transaction,
    IList<NodeAttributeOperationHandle> operationHandles,
    IList<ReadValueId> settings)
What you want to do is process requests as a batch by overriding both Read methods. For the synchronous version you must return null which tells the SDK to call the batch version. In the batch version you must hand off control to whatever thread you want to use for the processing. When processing completes you must invoke the callback which is part of the transaction one for each value. e.g:

Code: Select all

((ReadCompleteEventHandler)transaction.Callback)(
    transaction2.NodeHandles[ii],
    transaction2.CallbackData,
    new DataValue() { StatusCode = StatusCodes.BadNodeIdUnknown },
    false);
More information is here: http://doc.unifiedautomation.com/uasdkd ... anOverview


Best Regards,
Support Team