none
Multithreading or not RRS feed

  • Question

  • Hallo All

    I've been trying to make a decision on the following application for some time now, and cannot decide if it's wise to use multithreading or not.

    We are developing an application which is communicating via TCP - Modbus to controller on the shopfloor.

    The unit are needs to be constantly polled to check if there is data available, once there is data the there is a calling method that will collect the data from the controller and log it to SQL.

    The question now, will it be better to create some type of while loop with a single thread and just poll these units one at a time, or will it be wise to monitor each of these controllers in a seperate thread?

    There could be up to 20 controller in the field, the data is already store on the local controllers so the polling doesn't need to be very fast, it can be polled every couple of seconds.

    We do have two threads already, one to handle the inputs forms, and the second to handle the communication.

    Any input would be greatly appreciated, we need to complete the development over the weekend, and cannot decide on a way forward.

    Regards,


    labjac

    Thursday, November 8, 2018 5:11 AM

Answers

  • If the polling isn't time-critical then I guess it doesn't need to be multi-threaded, a single thread can easily round robin and it avoids complexity in your app.

    You might consider having the part which commits the data to SQL running on a separate thread to the code which is polling for events, with a queue between them - so that any slowdown in SQL server commits does not impact on the frequency at which you poll.

    • Marked as answer by labjac Thursday, November 8, 2018 11:20 AM
    Thursday, November 8, 2018 9:48 AM

All replies

  • If the polling isn't time-critical then I guess it doesn't need to be multi-threaded, a single thread can easily round robin and it avoids complexity in your app.

    You might consider having the part which commits the data to SQL running on a separate thread to the code which is polling for events, with a queue between them - so that any slowdown in SQL server commits does not impact on the frequency at which you poll.

    • Marked as answer by labjac Thursday, November 8, 2018 11:20 AM
    Thursday, November 8, 2018 9:48 AM
  • Thank you.

    And agree.. Will do as you suggest.

    Regards,



    labjac

    Thursday, November 8, 2018 11:19 AM