Dynamicall​y-Launched VIs and Context Switching

I'm working on a project that dynamically calls instances of a reentrant VI, which I assume is a pretty common practice. Everything works pretty well, until the number of calls to this dynamic VI gets pretty large--on the order of 1000 or more--at which point, we begin to see performance degradation. My guess is that we are taking hits due to context switching, since the number of threads far exceeds the number of logical processor cores available.
A little more background:
The dynamic VIs being called effectively run as daemons, each running a while loop and waiting on a dedicated input queue to receive data and save it to disk. All are stopped via a globally shared stop notifier (passed as a ControlValue.Set method argument at launch). Each is waiting on its respective queue with a 1 second timeout so that the stop notifier can be polled. Under normal operating conditions, each one will run at some rate between 0.1Hz and 25Hz (the various rates are a large driving factor for separating them and needing to spawn them dynamically).
So, this leads me to the following questions:
Am I correct that the context switching is the likely culprit in the performance degradation?
If so, is there a fundamental difference in how LabVIEW handles multithreading with dynamic VI calls versus explicitly drawing separate while loops on a block diagram, or dropping multiple instances of a reentrant VI directly on the block diagram?
Is it likely that reducing the number of dynamic clones to equal the number of available processor cores would improve performance? (the scope of each clone would grow, as it would have to maintain the state information that was original distributed across multiple clones)
I realize that this question is pretty vague without concrete examples, but I'm hoping someone (AQ? Ben? Any of you NI gurus?) out there could provide some general insight into what's going on under the hood without needing to get too specific.

TurboPhil wrote:
Each is waiting on its respective queue with a 1 second timeout so that the stop notifier can be polled.
There is one relatively easy fix you can probably make here - set the timeout to -1 and destroy the queues to stop the loop (destroying the queue will output an error from the wait primitive). This should at least stop all the code from running all the time, although I'm still not sure how the threading of the different VIs will play with each other. This might be an issue if the queue is only created in the VI, but I'm assuming it isn't.
Try to take over the world!

Similar Messages

  • Forcing context switching between Labview threads

    Hello,
     I have 2 threads interfacing with 2 serial ports on Labview ( Lets say Thread1 , is responsible for polling COM1 and Thread2 for polling COM2 ).
    By using occurrences, Thread1 executes before Thread2 and context switching is done according to Labview between the threads. Now, I'm looking to do the following :
    As soon as a specific block of code is executed in Thread1, I need Labview to force context switching to execute Thread2. I want to do this in order to synchronize the data received from the 2 threads.
    1- So, can this be done, or are there other ways for synchronization ?
    2- What if I want Labview to run as a real-time process or a higher priority thread on Windows XP in order to emulate the real-time effect on a Windows XP and not get any delays ? ( I already changed the process priority from the Process explorer, but there seems no effect. I also changed the Labview threads priority to real-time)
    3- Are there better approached for (1) & (2) ?  
    Thank you,
      Walid F. Abdelfatah 

    wfarid wrote:
    I already used occurrences for Thread1 to execute before Thread2. Does occurrences guarantee that Labview will switch the context to Thread2, as soon as the context is fired ?
    -- Walid 
    NO!
    LV depends on the OS to schedule threads. If you are sticking with Non-RT then you would be better off getting thread one to do the work while it has teh CPU.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Ipad screen is white. Restored it on iTunes. Press home and on switch goes black then back to white with no logo at all. Can't get past the white screen. This happened after running app updates. 16GB OS 7.1.1

    The ipad screen is white. Holding buttons didn't work so I restored it on iTunes. When I press home and on switch, the screen is white,  goes black then back to white with no logo at all. Can't get past the white screen. This happened after running app updates. Is there any fix besides going to Apple store? In iTunes on computer can see what is on there. 16GB OS 7.1.1

    FORCE IPAD INTO RECOVERY MODE
    1. Turn off iPad
    2. Turn on computer and launch iTunes (make sure you have the latest version of iTune)
    3. Plug USB cable into computer's USB port
    4. Hold Home button down and plug the other end of cable into docking port.
    DO NOT RELEASE BUTTON until you see picture of iTunes and plug
    5. Release Home button.
    ON COMPUTER
    6. iTunes has detected iPad in recovery mode. You must restore this iPad before it can be used with iTunes.
    7. Select "Restore iPad"...
    Note:
    1. Data will be lost if you do not have backup
    2. You must follow step 1 to step 4 VERY CLOSELY.
    3. Repeat the process if necessary.

  • Why is the mouse 'sticking' and it switches between windows?

    Hello,
    So this morning my mac has had a few issues, all within about a minute of each other:
    -mouse 'sticking', not totally frozen but isn't moving smoothly
    - will switch between open windows and even just fly over to the dashboard randomly
    -open random windows
             for ex. the little window that would open if I right clicked on something, (except I was just typing) and it's happened multiple times today, and never before.
    * I had Pages '09 and Safari open.
    * I've restarted my computer and only launched Safari  and the problem seems to have gone away, making me think there might be a corrupted file or something in Pages.
    Any suggestions would be much appreciated!
    Brandon

    The mouse (at least the Magic Mouse) sticking and flying are well known problems for which there seems to be no cure in sight. Just grit your teeth and try to think something complimentary about Apple.

  • Reg : Context-switching for built-in functions -

    Hi Experts,
    Asking this question just out of curiosity to know the internal concepts.
    In a SQL query often we use the in-built Oracle functions like LOWER, UPPER, etc.
    In this case, does context-switch happen?
    Will I be able to look into the code of these functions after logging into SYS schema as SYSDBA?
    FYI - I've Oracle XE 11.2 installed in my home pc (currently in office, so don't have access to it).
    Help much appreciated!
    Thanks,
    Ranit

    ranit B wrote:
    Hi Experts,
    Asking this question just out of curiosity to know the internal concepts.
    In a SQL query often we use the in-built Oracle functions like LOWER, UPPER, etc.
    In this case, does context-switch happen?No, because many of these functions are compiled at low level (C language) into the SQL and the PL/SQL engines, so each has their own 'copy' (in theory) to execute without having to context switch to the other engine.
    Will I be able to look into the code of these functions after logging into SYS schema as SYSDBA?No, they are written in C and compiled into the engines.
    In terms of the supplied packages (rather than built in functions), many of those are wrapped by oracle so you can only see the public interface, not the actual body code.

  • Overhead of SQL to PL/SQL context switch using an inline function

    Hi,
    We have a bit of sql in a third party application that uses an inline pl/sql function to do some security checks.
    These security checks are redundant in our system - we don't use the functionality so the result is always true, but the function is always called for each line of output, which is over a thousand for a lot of records.
    The function itself is fairly lightweight in our environment - the tables it uses are empty so each iteration of the function is quite quick (about .1 of a second per query in total, vs 12-15 seconds for the 'main' query). What I was wondering if there is any way of measuring the overhead of just doing the function calls.
    If I do a trace of the session I see the timings and cost of the 'main' sql query, and the breakdown of the 2 sql statements that have been called in the function (with over 1000 executions each) but is there any way to measure how much of the time to execute the main query is spent doing the context switch?
    Regards,
    Carl

    You could knock up some example to show the timings and measure it...
    The following shows an example using context switching from PL/SQL to SQL and back in a loop, which gives an idea of the performance difference...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_sysdate DATE;
      3  begin
      4    v_sysdate := SYSDATE;
      5    INSERT INTO mytable SELECT rownum FROM DUAL CONNECT BY ROWNUM <= 1000000;
      6    DBMS_OUTPUT.PUT_LINE('Single Transaction: Time Taken: '||ROUND(((SYSDATE-v_sysdate)*(24*60*60)),0));
      7    EXECUTE IMMEDIATE 'TRUNCATE TABLE mytable';
      8    v_sysdate := SYSDATE;
      9    FOR i IN 1..1000000
    10    LOOP
    11      INSERT INTO mytable (x) VALUES (i);
    12    END LOOP;
    13    DBMS_OUTPUT.PUT_LINE('Multi Transaction: Time Taken: '||ROUND(((SYSDATE-v_sysdate)*(24*60*60)),0));
    14    EXECUTE IMMEDIATE 'TRUNCATE TABLE mytable';
    15* end;
    SQL> /
    Single Transaction: Time Taken: 1
    Multi Transaction: Time Taken: 37
    PL/SQL procedure successfully completed.
    SQL>Likewise you could time a query with X number of rows calling a PL/SQL function and not calling a PL/SQL function to see the difference. The more rows you do, the better idea you'll get of the difference.
    ;)

  • How can i buy iphone if iam not a canadian but i am in toronto on visit visa  and i want to buy an iphone 5 ! please help me

    how can i buy iphone if iam not a canadian but i am in toronto on visit visa  and i want to buy an iphone 5 today coz i am going back to Pakistan tomorrow ! please help me fast !!!!

    Thanks FelipeV for your reply but i apple said they dont sell iphone who are not nationals as they need proof of address and your local ID and it happens in all apple stores around the world and even i cant buy online coz i have also show them a address and ID of any country where apple official launch the iphone. SO please please apple admin kindly answer my questions. Why i cant buy iphone if i am not a national of Canada ? i want to buy an iphone 5 today coz iam going back to pakistan tomrrow and i only came to toronto to buy an iphone. I am in Delta Chelsea near Eaton Centre and i want to buy iphone at any cost today. so please help me fast i am totally fed up !!!!

  • Why do some iOS 7 apps lose their state when I switch to another app and then switch back?

    When I switch from an app like Safari, the New York Times, Facebook, or Google+ Hangouts to some other app and then switch back, the first app takes me to its initial page, not to my place in the document I was reading. The Kindle app, on the other hand, seems to access the network but still manages to restore the page I was reading before the switch. I don't think my apps lost their place in earlier versions of iOS. Have other people noticed this? Is there something different in how iOS 7 switches context that requires apps to save their state differently than before? This problem is an annoying time-waster!

    Thanks for explaining how app's loss of state can happen. However, I'm sure that the behavior of the four apps I mentioned is much worse than just a few months ago. Something must have changed, and iOS 7 is the main difference. The Kindle app behaves as it used to, but the others do not. Maybe I should note the problem in reviews of the apps themselves in the App Store -- and down rate the apps.

  • Context switching.

    Theory: Firewalls essentially partition the Java Card platform’s object system into separate
    protected object spaces called contexts. The
    firewall is the boundary between one context and another. The Java Card RE shall
    allocate and manage a context for each Java API package containing applets1. All
    applet instances within a single Java API package share the same context. There is
    no firewall between individual applet instances within the same package. That is, an
    applet instance can freely access objects belonging to another applet instance that
    resides in the same package.
    That is the theory. What happens in my case. My Java Card project contains three packages and in one there is one Java Card applet. Splitting to three package was necessary because the application is large. What about the object instances from other packages. Are they assigned to other context and what happens when java card applet instance access these objects? Is context switching is happening?

    Patrick,
    Don't worry about context switching. Build a good load test. Run it against
    a "best guess" number of exec threads. Increase the number of threads and
    run again. If overall throughput drops, then decrease the number of threads
    and run again. Start with coarse increments (5 threads?) and work from there
    until you get the best setting.
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    http://www.tangosol.com/coherence.jsp
    Tangosol Coherence: Clustered Replicated Cache for Weblogic
    "Patrick Acheson" <[email protected]> wrote in message
    news:3d5aae20$[email protected]..
    >
    In setting the executeThreadCount variable for Weblogic 5.10, if thevariable is
    too high there will be a lot of context switching going on. What wouldconstitute
    a lot of context switching as opposed to what would be a normal orexpected amount?
    Our executeThreadCount is set at 100 and we have 4 CPUs. In Perfmon,about 10%
    of the threads show 1 to 2 context switches per second.

  • Context switching / Threads

    Hello !
    The following program is for 3 Threads which do context switching.
    Often we get '0' zero for the low priority thread when we run this program.
    MY QUESTION IS WHY DO WE GET ZERO ?
    As far as my understanding is concerned; even if preemptive multitasking is done by the threads,
    the low priority thread should have run through few iterations and thus giving some value other
    than zero '0'.
    Secondly most of the time we get negative values for the high priority thread. Why is that ?
    Is it because of the fact that volatile sets the variable 'running' to some different value ?
    The speed of my processor is 1.5GHz.
    GOD BLESS YOU.
    NADEEM.
    // Demonstrates threads priorities.
    class Clicker implements Runnable {
      int click = 0;
      String name ;
      Thread t ;
      private boolean running = true ;
      public Clicker(String tname, int p) {
       name = tname ;
       t = new Thread(this, name);
       t.setPriority(p);
       System.out.println("Current Thread is " + t + " " + t.getPriority());
      public void start() {
       t.start();
      public void run() {
       while (running) {
        click++;
      public void stop() {
       running = false ;
    class HLPriority {
    public static void main(String args[]) {
       System.out.println("Active Count : " + Thread.activeCount());
       Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
       Clicker hi = new Clicker("Hi", Thread.NORM_PRIORITY + 2);
       Clicker lo = new Clicker("Lo", Thread.NORM_PRIORITY - 2);
       System.out.println("Active Count : " + Thread.activeCount());
       lo.start();
       hi.start();
       try {
         System.out.println("Sleeping Thread : " + Thread.currentThread());
         Thread.sleep(10000);
       } catch (InterruptedException e) {
         System.out.println("Main Thread interrupted : " + e);
        hi.stop();
        lo.stop();
       try {
        hi.t.join();
        lo.t.join();
       } catch (InterruptedException e) {
         System.out.println("Interrupted Exception caught : " + e);
       System.out.println("Low priority thread  : " + lo.click);
       System.out.println("Hi  priority thread  : " + hi.click);
    }

    Hello !
    The following program is for 3 Threads which do
    context switching.
    Often we get '0' zero for the low priority thread when
    we run this program.
    MY QUESTION IS WHY DO WE GET ZERO ?Presumably because the low priority thread gets no CPU time.
    >
    As far as my understanding is concerned; even if
    preemptive multitasking is done by the threads,
    the low priority thread should have run through few
    iterations and thus giving some value other
    than zero '0'.You can't make ANY assumptions about when or how much CPU time a given thread will get. Why don't you let your main thread sleep longer--a minute or 5 or ten--and see if LO gets some cycles then.
    Secondly most of the time we get negative values for
    the high priority thread. Why is that ?count = Integer.MAX_VALUE;
    count++; // --> Integer.MIN_VALUE (-2^31)
    I guess 10 seconds is enough time for a thread in a tight loop to count to 2 billion.
    Is it because of the fact that volatile sets the
    variable 'running' to some different value ?Volatile does nothing of the sort, and, in any case, isn't even in your code.
    GOD BLESS YOU.I didn't sneeze.

  • Dynamically run multiple VIs and return values

    Dear Experts:
    I would like to dynamically run 8 VIs from a main VI that esentially do the exact same thing.  The only thing that is different is the data passed to the VIs and the data returned.  The VI has a loop that can possible run for ever and each of the 8 loops can be started at different points in time.  I figure I would use a functional global to pass controls to the VI (loop).  I am not sure how I will get data from each loop.  I can't use a functional global for this because there is no sequencial timing. The number 8 might change so I can't just make 8 loops in main.
    I would like to be a little more clear.  How do you return individual data from a VI that has been dynamically launched 8 times at different points in time?

    The data type of the queue needs to be a cluster.  One element being an ID of some sort (this ID should be passed into the subVI) and another element being the actual data.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • High thread context switching for java web application

    We have been load testing our java web application and observe high cpu usage with 50 users (which doesn't seem practical). The CPU shoots up above 80%. While profiling it with java flight recording (JFR) we see that the context switch rate is 8400 per second (as seen in the Hot threads tab on java mission control). Analyzing the hot threads in jfr, it seems the cpu usage is distributed across the application threads with each thread using less than 3% cpu.
    Increasing the user load to 100, 150 or 200 users we see the cpu shooting up above 90%, the throughput (transactions per second) remaining constant (as seen for 50 users load) while the response time crosses the acceptable threshold values (3 sec). Decreasing the user load to 20 users shows the cpu usage averages out to be above 55%. It certainly isn't true that the application threads are using up the cpu since our application is not a CPU bound application. The Hot Packages tab under Code tab group confirms this by showing that most of the time the application spends in is executing database queries.
    We use glassfish 3.1.2.2 as our application server where the max thread pool is configured to be of 100. Oracle Linux Server release 6.4 is our operating system with linux kernel version as 2.6.39-400.214.4.el6uek.x86_64. I tried executing linux commands namely "watch -n0.5 pidstat -w -I -p " and "watch -n.5 grep ctxt /proc//status" to see the voluntary and involuntary thread context switching at OS level but they don't give any results.
    Suspecting that high context switching could be causing the cpu to shoot up, do you have guidelines on what could be done to confirm that thread context switching is the cause of high cpu and what are there ways to tune the jvm or the application if that's the cause?
    Thanks!

    Kelum -
    We just saw this issue today for the first time. Have you been able to find a cause?
    We upgraded our 32bit Windows operating systems this weekend to use the /3GB flag. Since then, we have seen that our servers have ample heap space, but are dangerously low in PTE memory.
    But when we've been diagnosing the state of the server that produced this error (we run 2 nodes on 3 different computers; only 1 produced this error; the other 5 are working normally), everything looked fine. The server was reporting sufficient PTE availablility, plenty of heap space, and around 172 threads (we expect to be able to run many more than that).
    When we restarted the node, it came up fine and everything appeared to be working normally.
    So I'm looking for any clue as to the root cause, and what kind of resolution to explore. Any clues or pointers would be greatly appreciated.
    Paul Christmann

  • FORALL context switching .. how it works ?

    hi guys,
    in the asktom link over here
    <u>http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:17483288166654#17514276298239 </u>
    it was said that
    <i>
    forall i in 1 .. z_tab.count
    insert
    does this:
    a) gather up inpus to insert (the entire z_tab)
    b) perform context switch from PLSQL to SQL
    c) execute insert N-times
    d) perform context switch back from SQL to PLSQL
    </i>
    my question is does FORALL statement loops ?
    does it do this ?
    <b>Example 1</b>
    loop 1
    gather data to insert
    loop 2
    gather data to insert
    loop 3
    gather data to insert
    loop finish
    context switch to sql engine
    perform insert 1 by 1
    or
    <b>Example 2</b>
    loop 1 or no loop at all
    gather all data required for insert
    loop finish
    context switch to sql engine
    perform insert 1 by 1
    my guess is example 1 is the correct answer
    Advices gurus ?
    Regards,
    Noob

    At what level are you asking the question?
    In the context of PL/SQL, there is no loop. But if you pull back the layers and look at the intermediate language the procedure is compiled into, how the PL/SQL VM happens to implement those intermediate language instructions, how Oracle's C code happens to implement the VM, etc. it wouldn't shock me if there was some sort of loop-like construct in at least some level in some version of Oracle in some situation. Particularly depending on what you want to count as a loop at that level (somewhere in the SQL engine's C code, for example, Oracle might well have a loop when you're doing a full table scan, though it's probably not particularly useful to talk about a full table scan being in a loop)
    In addition, why are you asking the question? I cannot envision a functionality or performance difference between the two approaches, so it doesn't seem like something that would have any influence on how you use a particular PL/SQL construct.
    Justin

  • Thread context switching.

    Since I'm working with some real-time applications I'm interested in the thread switching mechanisms of Java ME.
    So my question is when does the context switching take place?
    If a thread A changes the priority of thread B to higher than its own priority will thread B preempt A instantly or is it neccessary to cause the current thread to interrupt?
    How do same priority threads preempt each other?
    What priority is given to the garbage collector?
    Mikael

    Hi Mikael,
    I'm not a ME VM expert, so do not have the deep knowledge. But from what I know:
    - thread switching can take place at any point during execution of java code. That's in interpreted mode. In compiled mode there are some limitations on when it can happen but it still could be described with the words "at almost any point"
    - the scheduler is called to have "fair" policy. That is - all threads get their share of CPU time, the priority defines how big this share is
    - the current thread get preempted when it's exhaused it's currently allocated share of CPU time. next thread is scheduled at that point
    - I don't know whether rescheduling happens when thread priority is modified
    - GC is not a thread and it does not have any priority. It gets invoked according to internal logic which does not depend on logic of the scheduler but rather on heap parameters (configuration and usage)
    Regards,
    Andrey

  • HT5012 I am having difficulty XMIT/REC text messages to family members using Android phones?  I have a 3GB data plan and all switches and buttons are set properly.  Any suggestions?

    I am having difficulty XMIT/REC text messages to family members using Android phones?  I have a 3GB data plan and all switches and buttons are set properly.  Any suggestions?

        Hello APVzW, we absolutely want the best path to resolution. My apologies for multiple attempts of replacing the device. We'd like to verify the order information and see if we can locate the tracking number. Please send a direct message with the order number so we can dive deeper. Here's steps to send a direct message: http://vz.to/1b8XnPy We look forward to hearing from you soon.
    WiltonA_VZW
    VZW Support
    Follow us on twitter @VZWSupport

Maybe you are looking for

  • WIN_API_DIALOG.OPEN_FILE & GET_FILE_NAME both not working in 3-tier

    Dear Friends, I want to Use open Dialog window for client Machine, So that user can Select any file. I am using Form 6i as front end, This thing have to be done by any means in forms 6i only. So does anybody have any idea over this. I Have used Get_F

  • Is there a way to download data into CSV format?

    Is there a way to download data into CSV format? I can't do this using delimiter as ',' because user wants the decimal format in the ','s only. Any suggestions?

  • My iPad mini and iPhone 4s don't show airplay button since last iOS upgrade

    I have an airport express connected to a stereo system and I used to play music with airplay from iTunes in either device or even my computer. Now the button disappeared. How do I get it back.

  • WLS11g How to start in STANDBY mode?

    Hello, I understand this was possible using weblogic.Admin (now deprecated). I assume it can be done with WLST, but help nodemanager and help lifecycle doesn't show how, neither does the documentation. thanks for your input, best wishes, B.

  • Pantalla rota

    tengo la pantalla rota de mi iphone 5 y me gustaria saber ya que se la e quitado si puedo dar mi movil y recibir uno nuevo con un precio no muy alto y como podria hacerlo.gracias