static public void Execute()
        {
            try {
                /*
                 * 1. Create RBroker instance using RBrokerFactory.
                 *
                 * This example creates a DiscreteTaskBroker.
                 */

                DiscreteBrokerConfig brokerConfig = new DiscreteBrokerConfig(Program.DEPLOYR_ENDPOINT);
                RBroker rBroker = RBrokerFactory.discreteTaskBroker(brokerConfig);

                /*
                 * 2. Register RTaskListener for asynchronous
                 * notifications on RTask completion.
                 */

                SampleTaskBrokerListener sampleListeners = new SampleTaskBrokerListener(rBroker);

                rBroker.addTaskListener(sampleListeners);
                rBroker.addBrokerListener(sampleListeners);


                /*
                 * 3. Define RTask
                 *
                 * This example creates a DiscreteTask that will
                 * execute an R script, /testuser/tutorial-rbroker/5SecondNoOp.
                 */

                RTask rTask = RTaskFactory.discreteTask(Program.TUTORIAL_NOOP_SCRIPT,
                                                        Program.TUTORIAL_REPO_DIRECTORY,
                                                        Program.TUTORIAL_REPO_OWNER,
                                                        "",
                                                        null);

                /*
                 * 4. Submit RTask to RBroker for execution.
                 *
                 * The RTaskToken is returned immediately. You can
                 * use the token to track the progress of RTask
                 * and/or block while waiting for a result.
                 *
                 * However, in this example we are going to allow
                 * the RTaskListener handle the result so
                 * there is nothing further for us to do here after
                 * we submit the RTask.
                 */

                RTaskToken rTaskToken = rBroker.submit(rTask);

                Console.WriteLine("DiscreteProfiling: submitted " + rTask +
                                  " for execution on RBroker.");
            }
            catch (Exception tex)
            {
                Console.WriteLine("DiscreteProfiling: ex=" + tex.ToString());
            }
        }
 /// <summary>
 /// Constructor for specifying a Pooled Instance of RBrokerWorker
 /// </summary>
 /// <param name="task">DiscreteTask reference</param>
 /// <param name="executorTaskRef">Reserved for future use</param>
 /// <param name="isPriorityTask">Boolean indicating this is a high priority task</param>
 /// <param name="resourceToken">integer referencing the token from the reosurce pool</param>
 /// <param name="rBroker">RBroker reference</param>
 /// <remarks></remarks>
 public PooledTaskWorker(PooledTask task,
                         long executorTaskRef,
                         Boolean isPriorityTask,
                         RProject resourceToken,
                         RBroker rBroker)
 {
     m_task            = task;
     m_executorTaskRef = executorTaskRef;
     m_isPriorityTask  = isPriorityTask;
     m_rProject        = resourceToken;
     m_rBroker         = (PooledTaskBroker)rBroker;
 }
 /// <summary>
 /// Constructor for specifying a Pooled Instance of RBrokerWorker
 /// </summary>
 /// <param name="task">DiscreteTask reference</param>
 /// <param name="executorTaskRef">Reserved for future use</param>
 /// <param name="isPriorityTask">Boolean indicating this is a high priority task</param>
 /// <param name="resourceToken">integer referencing the token from the reosurce pool</param>
 /// <param name="rBroker">RBroker reference</param>
 /// <remarks></remarks>
 public PooledTaskWorker(PooledTask task,
                         long executorTaskRef,
                         Boolean isPriorityTask,
                         RProject resourceToken,
                         RBroker rBroker)
 {
     m_task = task;
     m_executorTaskRef = executorTaskRef;
     m_isPriorityTask = isPriorityTask;
     m_rProject = resourceToken;
     m_rBroker = (PooledTaskBroker) rBroker;
 }
 /// <summary>
 /// Constructor for specifying a Discrete Instance of RBrokerWorker
 /// </summary>
 /// <param name="task">DiscreteTask reference</param>
 /// <param name="executorTaskRef">Reserved for future use</param>
 /// <param name="isPriorityTask">Boolean indicating if this ia high priority task</param>
 /// <param name="rClient">RClient reference</param>
 /// <param name="resourceToken">integer referencing the token from the reosurce pool</param>
 /// <param name="rBroker">RBroker reference</param>
 /// <remarks></remarks>
 public DiscreteTaskWorker(DiscreteTask task,
                           long executorTaskRef,
                           Boolean isPriorityTask,
                           RClient rClient,
                           int resourceToken,
                           RBroker rBroker)
 {
     m_task = task;
     m_executorTaskRef = executorTaskRef;
     m_isPriorityTask = isPriorityTask;
     m_rClient = rClient;
     m_resourceToken = resourceToken;
     m_rBroker = (DiscreteTaskBroker) rBroker;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Constructor for specifying a Discrete Instance of RBrokerWorker
 /// </summary>
 /// <param name="task">DiscreteTask reference</param>
 /// <param name="executorTaskRef">Reserved for future use</param>
 /// <param name="isPriorityTask">Boolean indicating if this ia high priority task</param>
 /// <param name="rClient">RClient reference</param>
 /// <param name="resourceToken">integer referencing the token from the reosurce pool</param>
 /// <param name="rBroker">RBroker reference</param>
 /// <remarks></remarks>
 public DiscreteTaskWorker(DiscreteTask task,
                           long executorTaskRef,
                           Boolean isPriorityTask,
                           RClient rClient,
                           int resourceToken,
                           RBroker rBroker)
 {
     m_task            = task;
     m_executorTaskRef = executorTaskRef;
     m_isPriorityTask  = isPriorityTask;
     m_rClient         = rClient;
     m_resourceToken   = resourceToken;
     m_rBroker         = (DiscreteTaskBroker)rBroker;
 }
 /// <summary>
 /// Constructor for specifying a Background Instance of RBrokerWorker
 /// </summary>
 /// <param name="task">BackgroundTask reference</param>
 /// <param name="executorTaskRef">Reserved for future use</param>
 /// <param name="isPriorityTask">Boolean indicating if this ia high priority task</param>
 /// <param name="rUser">RUser reference</param>
 /// <param name="resourceToken">integer referencing the token from the reosurce pool</param>
 /// <param name="rBroker">RBroker reference</param>
 /// <remarks></remarks>
 public BackgroundTaskWorker(BackgroundTask task,
                             long executorTaskRef,
                             Boolean isPriorityTask,
                             RUser rUser,
                             int resourceToken,
                             RBroker rBroker)
 {
     m_task = task;
     m_executorTaskRef = executorTaskRef;
     m_isPriorityTask = isPriorityTask;
     m_rUser = rUser;
     m_resourceToken = resourceToken;
     m_rBroker = (BackgroundTaskBroker) rBroker;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Constructor for specifying a Background Instance of RBrokerWorker
        /// </summary>
        /// <param name="task">BackgroundTask reference</param>
        /// <param name="executorTaskRef">Reserved for future use</param>
        /// <param name="isPriorityTask">Boolean indicating if this ia high priority task</param>
        /// <param name="rUser">RUser reference</param>
        /// <param name="resourceToken">integer referencing the token from the reosurce pool</param>
        /// <param name="rBroker">RBroker reference</param>
        /// <remarks></remarks>
        public BackgroundTaskWorker(BackgroundTask task,
                                    long executorTaskRef,
                                    Boolean isPriorityTask,
                                    RUser rUser,
                                    int resourceToken,
                                    RBroker rBroker) 
        {

            m_task = task;
            m_executorTaskRef = executorTaskRef;
            m_isPriorityTask = isPriorityTask;
            m_rUser = rUser;
            m_resourceToken = resourceToken;
            m_rBroker = (BackgroundTaskBroker) rBroker;

        }
        /*
         * RTaskAppSimulator method.
         */
        public void simulateApp(RBroker rBroker)
        {
            /*
             * 1. Prepare RTask(s) for simulation.
             *
             * In the example we will simply simulate the execution
             * a fixed number of RTask.
             *
             * Note, this is a somewhat artificial demo as we are
             * executing the same RTask SIMULATE_TOTAL_TASK_COUNT
             * times. You can experiment by modifying the
             * implementation to execute a range of RTask of
             * your own choosing.
             */

            RTask rTask = RTaskFactory.discreteTask(Program.TUTORIAL_NOOP_SCRIPT,
                                                    Program.TUTORIAL_REPO_DIRECTORY,
                                                    Program.TUTORIAL_REPO_OWNER,
                                                    "",
                                                    null);

            /*
             * 2. Loop submitting SIMULATE_TOTAL_TASK_COUNT
             * task(s) to RBroker for execution.
             */

            simulationStartTime = System.Environment.TickCount;

            for(int tasksPushedToBroker = 0;
                    tasksPushedToBroker<SIMULATE_TOTAL_TASK_COUNT;
                    tasksPushedToBroker++)
            {

                try
                {

                    RTaskToken taskToken = rBroker.submit(rTask);
                    Console.WriteLine("simulateApp: submitted task " +
                            rTask + " for execution on RBroker.");

                }
                catch(Exception ex)
                {
                    Console.WriteLine("simulateApp: ex=" + ex.ToString());
                }
            }
        }
        /*
         * RTaskAppSimulator method.
         */

        public void simulateApp(RBroker rBroker)
        {
            /*
             * 1. Prepare RTask(s) for simulation.
             *
             * In the example we will simply simulate the execution
             * a fixed number of RTask.
             *
             * Note, this is a somewhat artificial demo as we are
             * executing the same RTask SIMULATE_TOTAL_TASK_COUNT
             * times. You can experiment by modifying the
             * implementation to execute a range of RTask of
             * your own choosing.
             */

            RTask rTask = RTaskFactory.discreteTask(Program.TUTORIAL_NOOP_SCRIPT,
                                                    Program.TUTORIAL_REPO_DIRECTORY,
                                                    Program.TUTORIAL_REPO_OWNER,
                                                    "",
                                                    null);

            /*
             * 2. Loop submitting SIMULATE_TOTAL_TASK_COUNT
             * task(s) to RBroker for execution.
             */

            simulationStartTime = System.Environment.TickCount;

            for (int tasksPushedToBroker = 0;
                 tasksPushedToBroker < SIMULATE_TOTAL_TASK_COUNT;
                 tasksPushedToBroker++)
            {
                try
                {
                    RTaskToken taskToken = rBroker.submit(rTask);
                    Console.WriteLine("simulateApp: submitted task " +
                                      rTask + " for execution on RBroker.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("simulateApp: ex=" + ex.ToString());
                }
            }
        }
Exemplo n.º 10
0
        static public void Execute()
        {
            try
            {
                /*
                 * 1. Create RBroker instance using RBrokerFactory.
                 *
                 * This example creates an anonymous DiscreteTaskBroker.
                 */

                DiscreteBrokerConfig brokerConfig = new DiscreteBrokerConfig(Program.DEPLOYR_ENDPOINT, null, 5);

                RBroker rBroker = RBrokerFactory.discreteTaskBroker(brokerConfig);


                /*
                 * 2. Create an instance of RTaskAppSimulator. It will drive
                 * RTasks through the RBroker.
                 */

                SampleAppSimulation simulation = new SampleAppSimulation(rBroker);


                /*
                 * 3. Launch RTaskAppSimulator simulation.
                 */
                rBroker.simulateApp(simulation);

                /*
                 * 4. Block until all tasks are complete, and shutdown has been called
                 */
                rBroker.waitUntilShutdown();
            }
            catch (Exception tex)
            {
                Console.WriteLine("constructor: ex=" + tex.ToString());
            }
        }
 public ScoringEngineSimulation(RBroker rBroker)
 {
     m_rBroker = rBroker;
 }
        /*
         * RTaskAppSimulator method.
         */
        public void simulateApp(RBroker rBroker)
        {
            /*
             * 2. Submit task(s) to RBroker for execution.
             */

            Console.WriteLine("About to simulate " +
                    SIMULATE_TOTAL_TASK_COUNT + " tasks at a rate of " +
                    SIMULATE_TASK_RATE_PER_MINUTE + " tasks per minutes.");

            simulationStartTime = System.Environment.TickCount;

            for(int tasksPushedToBroker = 0;
                    tasksPushedToBroker<SIMULATE_TOTAL_TASK_COUNT;
                    tasksPushedToBroker++)
            {
                try {

                    /*
                     * 1. Prepare RTask for real-time scoring.
                     *
                     * In this example, we pass along a unique
                     * customer ID with each RTask. In a real-world
                     * application the input parameters on each RTask
                     * will vary depending on need, such as customer
                     * database record keys and supplimentary parameter
                     * data to facilitate the scoring.
                     */

                    PooledTaskOptions taskOptions = new PooledTaskOptions();
                    taskOptions.routputs.Add("score");
                    taskOptions.rinputs.Add(RDataFactory.createNumeric("customerid", tasksPushedToBroker));

                    RTask rTask = RTaskFactory.pooledTask(Program.TUTORIAL_RTSCORE_SCRIPT,
                                                Program.TUTORIAL_REPO_DIRECTORY,
                                                Program.TUTORIAL_REPO_OWNER,
                                                null, taskOptions);

                    RTaskToken taskToken = rBroker.submit(rTask);
                    Console.WriteLine("Submitted task " + rTask + "\n");

                    /*
                     * If further tasks need to be pushed to broker
                     * then delay for staggeredLoadInterval to simulate
                     * control of task flow rate.
                     */
                    if(tasksPushedToBroker < (SIMULATE_TOTAL_TASK_COUNT - 1))
                    {
                        try {

                            if(SIMULATE_TASK_RATE_PER_MINUTE != 0L)
                            {
                                int staggerLoadInterval = 60 / SIMULATE_TASK_RATE_PER_MINUTE;
                                Thread.Sleep(staggerLoadInterval * 1000);
                            }

                        }
                        catch(Exception iex)
                        {
                            Console.WriteLine("Runtime exception=" + iex.ToString());
                        }
                    }
                }
                catch(Exception ex)
                {
                    Console.WriteLine("Runtime exception=" + ex.ToString());
                }
            }
        }
 public SampleAppSimulation(RBroker rBroker)
 {
     m_rBroker = rBroker;
 }
        static public void Execute()
        {
            try
            {
                /*
                 * 1. Create RBroker instance using RBrokerFactory.
                 *
                 * This example creates a BackgroundTaskBroker.
                 */

                RAuthentication rAuth = new RBasicAuthentication(Program.AUTH_USER_NAME, Program.AUTH_PASSWORD);

                BackgroundBrokerConfig brokerConfig = new BackgroundBrokerConfig(Program.DEPLOYR_ENDPOINT, rAuth);
                RBroker rBroker = RBrokerFactory.backgroundTaskBroker(brokerConfig);

                /*
                 * 2. Register RTaskListener for asynchronous
                 * notifications on RTask completion.
                 */

                BackgroundTaskListener myTaskListener = new BackgroundTaskListener(rBroker);

                rBroker.addTaskListener(myTaskListener);


                /*
                 * 3. Define RTask
                 *
                 * This example creates a BackgroundTask that will
                 * execute an artibrary block of R code.
                 */

                String rCode = "x <- rnorm(100)";
                RTask  rTask = RTaskFactory.backgroundTask("Example Background RTask",
                                                           "Example background RTask.",
                                                           rCode,
                                                           null);

                /*
                 * 4. Submit RTask to RBroker for execution.
                 *
                 * The RTaskToken is returned immediately. You can
                 * use the token to track the progress of RTask
                 * and/or block while waiting for a result.
                 *
                 * However, in this example we are going to allow
                 * the RTaskListener handle the result so
                 * there is nothing further for us to do here after
                 * we submit the RTask.
                 */

                RTaskToken rTaskToken = rBroker.submit(rTask);

                Console.WriteLine("Submitted " + rTask + " for execution on RBroker.");

                /*
                 * 4. Block until all tasks are complete, and shutdown has been called
                 */
                rBroker.waitUntilShutdown();
            }
            catch (Exception tex)
            {
                Console.WriteLine("Runtime exception=" + tex.ToString());
            }
        }
 public ScoringEngineSimulation(RBroker rBroker)
 {
     m_rBroker = rBroker;
 }
 public BackgroundTaskListener(RBroker rBroker)
 {
     m_rBroker = rBroker;
 }
 public SampleTaskListener(RBroker rBroker)
 {
     m_rBroker = rBroker;
 }
 public SampleAppSimulation(RBroker rBroker)
 {
     m_rBroker = rBroker;
 }
        /*
         * RTaskAppSimulator method.
         */

        public void simulateApp(RBroker rBroker)
        {
            /*
             * 2. Submit task(s) to RBroker for execution.
             */

            Console.WriteLine("About to simulate " +
                              SIMULATE_TOTAL_TASK_COUNT + " tasks at a rate of " +
                              SIMULATE_TASK_RATE_PER_MINUTE + " tasks per minutes.");

            simulationStartTime = System.Environment.TickCount;

            for (int tasksPushedToBroker = 0;
                 tasksPushedToBroker < SIMULATE_TOTAL_TASK_COUNT;
                 tasksPushedToBroker++)
            {
                try {
                    /*
                     * 1. Prepare RTask for real-time scoring.
                     *
                     * In this example, we pass along a unique
                     * customer ID with each RTask. In a real-world
                     * application the input parameters on each RTask
                     * will vary depending on need, such as customer
                     * database record keys and supplimentary parameter
                     * data to facilitate the scoring.
                     */

                    PooledTaskOptions taskOptions = new PooledTaskOptions();
                    taskOptions.routputs.Add("score");
                    taskOptions.rinputs.Add(RDataFactory.createNumeric("customerid", tasksPushedToBroker));

                    RTask rTask = RTaskFactory.pooledTask(Program.TUTORIAL_RTSCORE_SCRIPT,
                                                          Program.TUTORIAL_REPO_DIRECTORY,
                                                          Program.TUTORIAL_REPO_OWNER,
                                                          null, taskOptions);

                    RTaskToken taskToken = rBroker.submit(rTask);
                    Console.WriteLine("Submitted task " + rTask + "\n");

                    /*
                     * If further tasks need to be pushed to broker
                     * then delay for staggeredLoadInterval to simulate
                     * control of task flow rate.
                     */
                    if (tasksPushedToBroker < (SIMULATE_TOTAL_TASK_COUNT - 1))
                    {
                        try {
                            if (SIMULATE_TASK_RATE_PER_MINUTE != 0L)
                            {
                                int staggerLoadInterval = 60 / SIMULATE_TASK_RATE_PER_MINUTE;
                                Thread.Sleep(staggerLoadInterval * 1000);
                            }
                        }
                        catch (Exception iex)
                        {
                            Console.WriteLine("Runtime exception=" + iex.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Runtime exception=" + ex.ToString());
                }
            }
        }
 public BackgroundTaskListener(RBroker rBroker)
 {
     m_rBroker = rBroker;
 }
Exemplo n.º 21
0
        static public void Execute()
        {
            RBroker rBroker = null;

            try
            {
                /*
                 * 1. Create RBroker instance using RBrokerFactory.
                 *
                 * This example creates a DiscreteTaskBroker.
                 */

                DiscreteBrokerConfig brokerConfig = new DiscreteBrokerConfig(Program.DEPLOYR_ENDPOINT);
                rBroker = RBrokerFactory.discreteTaskBroker(brokerConfig);


                /*
                 * 2. Define RTask
                 *
                 * This example creates a DiscreteTask that will
                 * execute an R script, /testuser/tutorial-rbroker/5SecondNoOp.
                 */

                RTask rTask = RTaskFactory.discreteTask(Program.TUTORIAL_NOOP_SCRIPT,
                                                        Program.TUTORIAL_REPO_DIRECTORY,
                                                        Program.TUTORIAL_REPO_OWNER,
                                                        "",
                                                        null);


                /*
                 * 3. Submit RTask to RBroker for execution.
                 *
                 * Note, unlike an RClient.executeScript call or
                 * an RProject.executeScript call the RBroker.submit
                 * call is non-blocking.
                 *
                 * The RTaskToken is returned immediately. You can
                 * use the token to track the progress of RTask
                 * and/or block while waiting for a result.
                 */

                RTaskToken rTaskToken = rBroker.submit(rTask);

                Console.WriteLine("DiscreteBlocking: submitted " + rTask + " for execution on RBroker.");

                /*
                 * 4. Demonstrate blocking for an RTask result.
                 *
                 * The call to getResult() will either return
                 * an RTaskResult or raise an Exception. An Exception
                 * indicates the RTask failed to complete and why.
                 */

                RTaskResult rTaskResult = rTaskToken.getResult();

                Console.WriteLine("DiscreteBlocking: " + rTask + " completed, result=" + rTaskResult.getTimeOnCall());
            } catch (Exception tex)
            {
                Console.WriteLine("DiscreteBlocking: error=" + tex.ToString());
            }
            finally
            {
                /*
                 * Final Step: Shutdown RBroker to release
                 * all associated resources, connections.
                 */
                if (rBroker != null)
                {
                    rBroker.shutdown();
                    Console.WriteLine("DiscreteBlocking: rBroker has been shutdown.");
                }
            }
        }
        static public void Execute()
        {
            try
            {
                /*
                 * 1. Prepare PooledBrokerConfig instance.
                 *
                 * This example creates an authenticated PooledTaskBroker
                 * to act as our scoring engine.
                 *
                 * The following steps initialize the pool of
                 * R sessions dedicated to our scoring engine.
                 *
                 * In this example, we pre-initialize the workspace
                 * for each R session in the pool to contain the
                 * R model used when scoring customer requests.
                 *
                 * The R model, insurModel.rData, is loaded from
                 * the DeployR repository into each workspace at
                 * startup time. Preloading the R model at startup
                 * reduces runtime overhead and improves overall
                 * response times in the application.
                 */
                RAuthentication rAuth = new RBasicAuthentication(Program.AUTH_USER_NAME, Program.AUTH_PASSWORD);

                PoolCreationOptions poolOptions = new PoolCreationOptions();

                PoolPreloadOptions preloadOptions = new PoolPreloadOptions();
                preloadOptions.filename  = Program.TUTORIAL_INSURANCE_MODEL;
                preloadOptions.directory = Program.TUTORIAL_REPO_DIRECTORY;
                preloadOptions.author    = Program.TUTORIAL_REPO_OWNER;

                poolOptions.preloadWorkspace = preloadOptions;


                /*
                 * 2. Create RBroker instance.
                 *
                 * The application designer, in conjunction with the
                 * DeployR administrator who provisions and sets
                 * limits on DeployR grid resources, need to decide how
                 * many R sessions will be reserved for the PooledRBroker
                 * used by our scoring engine application.
                 */

                int TARGET_POOL_SIZE = 10;

                PooledBrokerConfig brokerConfig = new PooledBrokerConfig(Program.DEPLOYR_ENDPOINT,
                                                                         rAuth,
                                                                         TARGET_POOL_SIZE,
                                                                         poolOptions);

                Console.WriteLine("About to create pooledTaskBroker.");

                RBroker rBroker = RBrokerFactory.pooledTaskBroker(brokerConfig);

                Console.WriteLine("R session pool size, requested: " +
                                  TARGET_POOL_SIZE + " , actual: " +
                                  rBroker.maxConcurrency() + "\n");


                /*
                 * 3. Create an RTaskAppSimulator. It will drive
                 * sample customer data scoring requests through the
                 * RBroker.
                 */

                ScoringEngineSimulation simulation = new ScoringEngineSimulation(rBroker);


                /*
                 * 4. Launch RTaskAppSimulator simulation.
                 */

                rBroker.simulateApp(simulation);

                /*
                 * 5. Block until all tasks are complete, and shutdown has been called
                 */
                rBroker.waitUntilShutdown();
            }
            catch (Exception tex)
            {
                Console.WriteLine("constructor: ex=" + tex.ToString());
            }
        }
 public SampleTaskBrokerListener(RBroker rBroker)
 {
     m_rBroker = rBroker;
 }