MultiThreading

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
Shazard
Posts: 25
Joined: 21 Jun 2014 13:41

MultiThreading

Post by Shazard »

Does ZWave.Me JSON API supports parallel requests.

I mean if I will execute different API requests in parallel without waiting previous to return, will I mess up response states, or I will get correct answers.

What I am doing is that when I get /ZWaveAPI/Data/[timestamp] response, I go for each device and try to get it's state. For example if I receive
{ devices.2.instances.0.commandClasses.37.somethign} I go for /ZWaveAPI/Run/devices[2].instances[0].commandClasses[37] request

Question is if I will execute in parallel (without waiting previous to return) lot of requests for all such devices/instances will I get respionse correctly?

Also what if I drop Get() method invocation in the mix - of course that is blocking call, I will wait until it returns for particular device to poll it's state...
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: MultiThreading

Post by pofs »

There's no reason to perform parallel requests, because v8 js engine is single-threaded by design.

Most of devices correctly report their status without need to call Get, so you'll just make a lot of excessive load for both server and z-wave network. Don't do it without a dead serious reason.

For those devices which don't report their status correctly, you may create a server-side js to poll value. Again, there's no reason to bring these workarounds to client, leave them on server. Client should only listen for status changes and update interface accordingly (and call functions to change when needed).
Shazard
Posts: 25
Joined: 21 Jun 2014 13:41

Re: MultiThreading

Post by Shazard »

Hi, thanks for response, but I suppose you didn't understood the scenario.

The "clien" is Android device without any JS, it's pure POST HTTP requests on REST API for Zwave.me.

So what am I doing is actually the same what JS does, only through java power. So in general what I do

1. I ask for /ZwaveAPI/Data/[timestamp] request, and get the response
2. If the response contains changed devices, only then and only those devices are polled for data updates (as my previous post indicated, sometimes I need to enforce Get())

Question is if I execute those polls in parallel will I get correct responses? My current version does it in sequence, and it works, but I don't know if it will work if I just poll all the changed devices at the same time...

Or the REST API is itself served by JS engine?
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: MultiThreading

Post by pofs »

All API requests are served by JS engine, so there's no reason to execute them in parallel. (/ZWaveAPI/Data/ is the only request not served by JS, but that will change in the nearest future)
Shazard wrote:So what am I doing is actually the same what JS does, only through java power
That's exactly what I'm encouraging you not to do.

Don't bring under-the-hood logic to client.
Each device is broken in its own way, so you need to add very device-specific hacks. For example, TKBHome sends NIF on manual on/off, so you can workaround the issue in that way. But some other device won't send it, and your logic will still fail to correctly display status.
Furthermore, it can change anytime (device replaced with a newer version, firmware updated, added some new device to network, …), so you'll be required to change, rebuild and update your client app instead of simply adding/removing some tiny JS module to workaround specific issue.
Shazard
Posts: 25
Joined: 21 Jun 2014 13:41

Re: MultiThreading

Post by Shazard »

Thanks. That answers.

p.s. no big logic in client anyway... but thanks for warning
Post Reply