4 Replies Latest reply on Feb 27, 2013 12:48 AM by hsuzuki

    Debug mode and Service mode


      Hi vCampus team,


      I'm writing a codes on ACE and I have a question about a performance between debug mode and service mode.  When I executed below codes, it took 9 seconds. But it took 26 seconds when I execute this in the PI ACE 2.x Scheduler service. This program reads text csv file which has a list of 3600 tag name and retrieves the PI tag attributes (i.e. descriptor and engunits) for each PI tags. I'd like to know what difference between debug mode (takes 9 seconds) and service mode (takes 26 seconds). ACE version is 2010 R2 SP1 and PI Server version 3.4.364.32 as a separate box.




      In the InitializePIACEPoints()...


               Dim csvname As String = "C:\config\ACE.cfg"


               myPIServer.MessageLog.PutString("Start1 :InitializePIACEPoints" + System.DateTime.Now)

                  Using parser As New TextFieldParser(csvname, System.Text.Encoding.GetEncoding("Shift_JIS"))
                      parser.TextFieldType = FieldType.Delimited
                      While Not parser.EndOfData
                          Dim row As String() = parser.ReadFields()
                          row(0) = row(0).Replace(vbCrLf, "n")
                          ptList2 = igp2.GetPoints2("tag = '" + row(0) + "'", retAttributes, GetPointsRetrievalTypes.useGetPoints)
                          If ptList2.Count > 0 Then
                              pt = ptList2.Item(1)
                              errFlag = True
                          End If
                      End While
                  End Using
              myPIServer.MessageLog.PutString("End :InitializePIACEPoints" + System.DateTime.Now) 



      Hiroyuki Suzuki


      Customer Support Engineer


      OSIsoft Japan



        • Re: Debug mode and Service mode

          Hi Hiroyuki-san


          I think the reason you are getting this performance difference is because when the dll is executed by the PI ACE Scheduler, it is running in a MTA thread. When you are working with PI SDK in MTA threads, the PI SDK objects may need to be marshalled between threads during the execution and this incurs overhead. Other than PI ACE this also happens when PI SDK is deployed in projects or applications that uses MTA threads as well like web application and windows service application. You can probably find a number of threads in the forums here, searching for the keyword MTA vs STA.


          One way to workaround this is to run the code using PI SDK in a STA thread instead. meaning you can write a method for that and start a new thread and define its thread apartment type to be STA and execute the method in new thread, like the example 2 pointed out in this techsupport article. The example is for writing values with annotation in PI ACE using PI SDK, but the concept should work for you as well. 

            • Re: Debug mode and Service mode

              Hi Han Yong-san,


              I understand this MTA behavior and its information is helpful for me.





                • Re: Debug mode and Service mode

                  One other thought; are you using naturally triggered calculations by any chance?


                  If so, check what the latency settings are for your calculation are in the PI-ACE manager. I believe that the default latency is 15 seconds, so if your original calculation took 9 seconds to execute, that is getting close to 26 seconds.


                  The screenshot below shows a 15-second latency for a naturally trigger test calculation I had created once. The latency won't show up when you test/debug your calculation in Visual Studio. However, when you run it under the ACE scheduler, it should be applying the latency that is specified in the context setup.