LocalStorage / Scope Type is not in sync over multiple instances

Created at 05 Apr 2024, 07:45
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
WO

wolters

Joined 25.03.2022

LocalStorage / Scope Type is not in sync over multiple instances
05 Apr 2024, 07:45


Hi.

 

I'm using LocalStorage / Scope Type. As long as the localStorage is not flushed/reloaded every time, the LocalStorage at least for scope “type" is not in sync over mutliple instances of the same indicator.
It feels as if there is a LocalStorage instance for each indicator-instance instead of a single instance for each indicator type.

 

Could you make sure that accessing the LocalStorage by multi instances always return the latest values without flushing/reloading and not returning some cached ones?

 

Best
Carsten


@wolters
Replies

PanagiotisCharalampous
05 Apr 2024, 09:03 ( Updated at: 05 Apr 2024, 09:06 )

Hi there,

It is by design that you need to flush and load your changes in order to see them in another instance instantly.

Best regards,

Panagiotis


@PanagiotisCharalampous

wolters
05 Apr 2024, 09:22 ( Updated at: 05 Apr 2024, 09:26 )

RE: LocalStorage / Scope Type is not in sync over multiple instances

PanagiotisCharalampous said: 

Hi there,

It is by design that you need to flush and load your changes in order to see them in another instance instantly.

Best regards,

Panagiotis

Hi Panagiotis,

even flush+load does not guarantee that the values in the other process do get refreshed.
I tried it, but is does not work consitently. Workflow:

Indicator-Instance 2:

LocalStorage.SetObject("test", “doesNotGetOverwritten”, LocalStorageScope.Type);

 

Indicator-Instance 1: 

LocalStorage.SetObject("test", “shallOverwrite”, LocalStorageScope.Type);
LocalStorage.Flush();


Indicator-Instance 2:

LocalStorage.Reload();
LocalStorage.GetObject("test", LocalStorageScope.Type) ≠ “shallOverwrite”;
 

In the last step, I cannot be sure that the LocalStorage of instance 2 does get the correct value of instance 1. Possibly, it gets overwritten by the content of instance 2, because the initial changes in instance 2 were not flushed initially and will be written at a later time - after instance 1 changed the values.

Flushing/Reloading all the time is very nasty and reduces the performance a lot.

 

If there is already a storage on the “type”-level, there is no reason to not be in sync over different instances. Please re-think about this. It would be nice to have a consistent access to values without flush/reload.

 

Best
Carsten

 


@wolters

PanagiotisCharalampous
05 Apr 2024, 12:11 ( Updated at: 05 Apr 2024, 12:14 )

Hi Carsten,

Well this is not a cTrader issue but a general programming concept. When two threads try to access the same resource at the same time, then such issues happen. You need to implement some kind of control, like using a mutex 

Regarding

If there is already a storage on the “type”-level, there is no reason to not be in sync over different instances. Please re-think about this. It would be nice to have a consistent access to values without flush/reload.

As you mentioned before this is resource consuming, therefore it happens automatically by design every minute.

Best regards,

Panagiotis


@PanagiotisCharalampous

wolters
06 Apr 2024, 12:14 ( Updated at: 07 Apr 2024, 05:30 )

RE: LocalStorage / Scope Type is not in sync over multiple instances

Hi Panagiotis,

I know all of this, but it still would be nice to have the mutex/thread-safe access to the LocalStorage on Type & Instance level done by cTrader and not by an error prone user implementation.

As a user I would assume, that I do no need to care about syncing stuff (I should not even think about flushing/reloading) and just use the LocalStorage on Type&Instance level. The implementation in the background should take care that it is an atomic access to the “global” storage. And this is not the case right now, so it lacks these features whichs makes things uneccessary complex.

So if possible, please extend your implementation to guarantee a thread safe behavior across multiple instances when using LocalStorage.

 

Best,
Carsten

 

 

PanagiotisCharalampous said: 

Hi Carsten,

Well this is not a cTrader issue but a general programming concept. When two threads try to access the same resource at the same time, then such issues happen. You need to implement some kind of control, like using a mutex 

Regarding

If there is already a storage on the “type”-level, there is no reason to not be in sync over different instances. Please re-think about this. It would be nice to have a consistent access to values without flush/reload.

As you mentioned before this is resource consuming, therefore it happens automatically by design every minute.

Best regards,

Panagiotis

 


@wolters

PanagiotisCharalampous
07 Apr 2024, 06:16

RE: RE: LocalStorage / Scope Type is not in sync over multiple instances

wolters said: 

Hi Panagiotis,

I know all of this, but it still would be nice to have the mutex/thread-safe access to the LocalStorage on Type & Instance level done by cTrader and not by an error prone user implementation.

As a user I would assume, that I do no need to care about syncing stuff (I should not even think about flushing/reloading) and just use the LocalStorage on Type&Instance level. The implementation in the background should take care that it is an atomic access to the “global” storage. And this is not the case right now, so it lacks these features whichs makes things uneccessary complex.

So if possible, please extend your implementation to guarantee a thread safe behavior across multiple instances when using LocalStorage.

 

Best,
Carsten

 

 

PanagiotisCharalampous said: 

Hi Carsten,

Well this is not a cTrader issue but a general programming concept. When two threads try to access the same resource at the same time, then such issues happen. You need to implement some kind of control, like using a mutex 

Regarding

If there is already a storage on the “type”-level, there is no reason to not be in sync over different instances. Please re-think about this. It would be nice to have a consistent access to values without flush/reload.

As you mentioned before this is resource consuming, therefore it happens automatically by design every minute.

Best regards,

Panagiotis

 

Hi Carsten,

Thanks for your suggestion. At the moment, we believe that this type of decision making needs to take place at the cBot's developer level and not on the API level. For most implementations, all this built in complexity would just incur unnecessary overhead to the end user. The vast majority of applications does not require a thread safe implementation so we do not see a reason to force it.

Best regards,

Panagiotis


@PanagiotisCharalampous