Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
SKK 4.0.2-808 is com.prosysopc.ua.client.AddressSpace.getNode thread safe?
August 20, 2019
17:57, EEST
Avatar
Christv
Member
Members
Forum Posts: 9
Member Since:
August 9, 2016
sp_UserOfflineSmall Offline

In thread dump I see a lot blockes on the com.prosysopc.ua.client.AddressSpace.getNode method, I use this method in multithread application in read or write to a tag.

java.lang.Thread.State: BLOCKED
at com.prosysopc.ua.client.AddressSpace.getNode(SourceFile:885)
at com.bekaert.osgi.datakap.opcuaclient.OpcUaServer.tagRead(OpcUaServer.java:1389)

java.lang.Thread.State: BLOCKED
at com.prosysopc.ua.client.AddressSpace.getNode(SourceFile:885)
at com.bekaert.osgi.datakap.opcuaclient.OpcUaServer.tagWrite(OpcUaServer.java:1484)

August 21, 2019
16:13, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1026
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Yes, it is thread-safe, but it is also synchronized. If the node doesn’t exist in the AddressSpace.getNodeCache() or is old enough there (NodeCache.getNodeMaxAgeInMillis), the getNode will fetch it from the server (Attributes and References), which will take time (3 service calls). If you use it in repeated reads/writes it is quite likely that threads will block on that while service calls happen.

Generally it is better to use UaClient.read and write methods for reading and writing the Value Attribute repeatedly.

August 21, 2019
17:07, EEST
Avatar
Christv
Member
Members
Forum Posts: 9
Member Since:
August 9, 2016
sp_UserOfflineSmall Offline

I use this method to get datatype of variant value, as there is no getDatatype method in Variant class

variable = (UaVariable) client.getAddressSpace().getNode(nodeId);
NodeId dataTypeId = variable.getDataTypeId();
UaType dataType = variable.getDataType();
if (dataType == null) dataType = client.getAddressSpace().getType(dataTypeId);

August 29, 2019
13:17, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1026
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Most of the time the DataType of a node shouldn’t change. Therefore you should be able to just read that once and cache it in e.g. a Map.

Note that while it is true that the Variant doesn’t contain the specific DataType as a NodeId, in some cases just the java class of the value would be enough. However even if that is not enough, it is still be more performant to Read the DataType Attribute before doing the Write/Read vs. calling getNode(). But note that if you do it faster than 1 second (which is the default cache time of the NodeCache of the AddressSpace), then Reading the DataType will probably start to take more time depending how fast you are writing.

Additionally note that the UaClient.read/write methods you can do bulk operations, i.e. read/write to multiple nodes at once, which probably gives better performance if you can group the operations somehow in your application.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
13 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Heikki Tahvanainen: 402

hbrackel: 144

rocket science: 88

pramanj: 86

Francesco Zambon: 83

Ibrahim: 78

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

Member Stats:

Guest Posters: 0

Members: 736

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1524

Posts: 6450

Newest Members:

kristiewinkle8, rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerley, Thomassnism

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0

Administrators: admin: 1