LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Performance of Data Socket and Database insertion

My callback function which reads the values from the Data Socket Server which is running on remote machine.  With in callback function i calculate the Alarm condition and generates the alarm if any. On an average 100 alarms are getting generated out of 512 different values which i reading from datasocket server. For all generated alarm i am logging into database (SQL Server 2000) which is presently running on the same machine and also the same alarms i writing to another data socket port. My callback gets event almost every second. Due to these heavy database logging (is it really heavy per sec 100 data base insertion with in a call back ?) i loose the data socket connection after few seconds. Why ? Please advice me

Thanks and Regards

R K Gupta

0 Kudos
Message 1 of 5
(3,492 Views)

If you need to do something potentialy time consuming, then it is best to NOT do this in any callback function (DataSocket, UI, TCP, etc) - because it will block the upstream processing and could lead to data-loss, etc. Instead, you should consider storing the data in some buffer and using a worker thread to do the time consuming task. This way you can separate the two tasks. Probably, the best way to achieve this in CVI is to use a thread safe queue (see the Utility library functions and thread-safe-queue example programs) to store and process the data. Also, DataSocket has a "polling" model (see DS_OpenEx and the DataSocket polling example program) where you can poll for data instead of getting data-updated events in the callback. You may want to consider one of these approaches (thread safe queue or polling DataSocket model) if you need to do some time-consuming tasks with the data.

Best regards,

Mohan

0 Kudos
Message 2 of 5
(3,484 Views)
Hello Mohan
 
As suggested by you i made the necessary modification and now using  thread safe queue but i am not finding any improvement.  I am attaching herewith the source code. Please let me if there is any mistake or give your suggestion to improve the the performance.
 
Thanks a lot
 
Regards
Rakesh 
0 Kudos
Message 3 of 5
(3,474 Views)

Hi Rakesh,

I just meant to give some suggestions that might help you solve your application problems. I was not volunteering to consult on your project. In general, when an application has latencies in executing multiple tasks, one possible solution is to partition the tasks on to different threads, and that was what I suggested. If that is not solving your problem, the latencies might be else where in your application, and you need to do more debugging and analyze the time-behavior of your program to come up with a solution.

Thanks,

- Mohan

0 Kudos
Message 4 of 5
(3,455 Views)
Thanks Mohan...
0 Kudos
Message 5 of 5
(3,440 Views)