www.homeseer.com    
 

Go Back   HomeSeer Message Board > Lighting & Primary Technology Plug-ins > Lighting & Primary Technology Discussion > Insteon Plug-in (Mark Sandler)

Insteon Plug-in (Mark Sandler) Discussions related to Mark Sandler's 3rd parth plug-in for controlling Insteon devices via Smarthome's PLM interfaces (the 2412 & 2413 series controllers)

Reply
 
Thread Tools Display Modes
  #1  
Old August 5th, 2010, 08:39 PM
ddv ddv is offline
Seer
 
Join Date: Jan 2008
Location: RUS
Posts: 32
Very slow INSTEON perfomance with plugin.

Hi,

I have very slow INSTEON performance with plug-in.. If I send two INSTEON commands to two different devices then second command delayed on 1-5 seconds. I found that plug-in processes commands one by one waiting for the result of execution of each command. Moreover, if the device does not respond, the plug can wait up to 5 seconds and delay execution of remaining commands.Why do not you make asynchronous execution of commands by sending requests one by one and processing the results separately?

Best Regards,
Dmitry
Reply With Quote
  #2  
Old August 5th, 2010, 11:29 PM
JeffryD
Guest
 
Posts: n/a
It's the nature of Insteon itself. The line can only carry one message at a time. The bandwidth is barely enough for that. The plug-in can't do anything to work around this limitation.
Reply With Quote
  #3  
Old August 5th, 2010, 11:54 PM
ddv ddv is offline
Seer
 
Join Date: Jan 2008
Location: RUS
Posts: 32
Quote:
Originally Posted by JeffryD View Post
It's the nature of Insteon itself. The line can only carry one message at a time. The bandwidth is barely enough for that. The plug-in can't do anything to work around this limitation.
You are wrong. Insteon protocol don't have this limitation. Where are you find this information? Only one message can be TRANSMITTED at the time. But between request and response it can support many OTHER requests and responses from OTHER devices. But your plug-in does not send any other requests while waiting response from specific device...and it is wrong. Line is free at this moment and other devices can communicate at this time but not plug-in. INSTEON protocol can support from 36 to 160 standard messages per second but your plugin limit it to maximum 4 (2 requests + 2 responses) messages per second. Because pure plug-in message speed is 5 messages per second (100ms delay on transmit after each message + 100ms delay on receive after each message) + minimum 300 ms delay for device response. Your plug-in can work in 9-32 times faster!!!!
More that, I found that your programmer don't understand multithreaded programming at all. He use Queue for pass messages to another threads but it is NOT THREAD SAFE. Only TransmitMsgThread try to use thread safe Queue BUT it STILL NOT THREAD SAFE because all other threads use THIS Queue WITHOUT lock!!! You MUST use thread safe Queue in EVERY thread! It work ONLY because you use BIG delays (100ms) on every step. It is very bad idea. You should use AutoResetEvent to Thread Synchronization and LOCK EVERY action with Queue.
If you want I can help you to improve your plug-in for free...because I plan to use it

Best Regards,
Dmitry

Last edited by ddv; August 6th, 2010 at 12:15 AM.
Reply With Quote
  #4  
Old August 10th, 2010, 09:36 PM
mnsandler's Avatar
mnsandler mnsandler is offline
Insteon Overlord
 
Join Date: Apr 2005
Location: Virginia
Posts: 10,698
Dmitry,

would you care to share some sample code of the thread safe code and queueing mechanism you mentioned
__________________
Mark

HS3 Pro 3.0.0.368
Hardware: Insteon Serial PLM | Vista Alarm 20P with AD2USB | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway
Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 (by Kirby) | Ultra1Wire3 | RFXCOM | NetCAM | MyQ | BLRadar | BLDenon | Jon00 Charting
Platform: HP h8-1360t, Windows Server 2012 R2, i7-3.4GHz, 16GB memory
Reply With Quote
  #5  
Old August 11th, 2010, 01:17 PM
ddv ddv is offline
Seer
 
Join Date: Jan 2008
Location: RUS
Posts: 32
Quote:
Originally Posted by mnsandler View Post
would you care to share some sample code of the thread safe code and queueing mechanism you mentioned
ok.
1. All Queue's (gTransmitMsgQueue, gReceivedInsteonRaw, gReceivedInsteonText) that you use must be SynchronizedQueue. Because only SynchronizedQueue use lock for Dequeue/Enqueue. You use SynchronizedQueue only in TransmitMsgThread() but all other methods (TransmitGroupCommand, TransmitDeviceCommand and etc) use same queue (gTransmitMsgQueue) without lock.

2. Use AutoResetEvent instead of Thread.Sleep(100). For each queue declare AutoResetEvent like "AutoResetEvent gTransmitMsgQueueEvent = new AutoResetEvent(false)". Add gTransmitMsgQueueEvent.Set() after each Enqueue for this queue. Add same for each queue in ShutdownPlugin method just after "gShutdown = true" to unlock threads. Replace Thread.Sleep(100) to gTransmitMsgQueueEvent.WaitOne(100) in TransmitMsgThread(). In other methods use proper event name for each queue.

3. ResourceManager is absolutly not thread safe (several threads can simultaneously enter to any method and simultaneously check that it is FREE on same resource). Just use array of ReaderWriterLock in ResourceManager. It exactly what you want to implement (AcquireReaderLock for locks and AcquireWriterLock for exclusive locks).

To increase performance you have to change transmit logic. Now you transmit the data and wait result in same method in same thread. It should be divided. One thread should only transmit messages and ANOTHER thread should wait and process results for each transmission. It look like transactions...One thread start transaction and another thread process it result or retransmit it if no results received. Only need to provide when the same device has several transactions that do not start new until old will be done.


Best Regards,
Dmitry

Last edited by ddv; August 11th, 2010 at 02:05 PM.
Reply With Quote
  #6  
Old August 11th, 2010, 02:40 PM
mnsandler's Avatar
mnsandler mnsandler is offline
Insteon Overlord
 
Join Date: Apr 2005
Location: Virginia
Posts: 10,698
thanks i will take a look at these queues, etc.

out of curiousity, what tool did you use to reverse engineer/decompile the dll to see the level of detail you are quoting above?
Reply With Quote
  #7  
Old August 11th, 2010, 04:04 PM
ddv ddv is offline
Seer
 
Join Date: Jan 2008
Location: RUS
Posts: 32
Quote:
Originally Posted by mnsandler View Post
out of curiousity, what tool did you use to reverse engineer/decompile the dll to see the level of detail you are quoting above?
I use Reflector.NET

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 11:10 PM.


Copyright HomeSeer Technologies, LLC