Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

Implemented Multithreading using run base batch , but batch run time is not decreasing !! help

Posted on by 490

I have implemented multithreading using run base batch framework but when I run it, it gets multiple tasks, but batch run time did not decreased (tested same logic without multithreading in both cases time is same) I am adding my code, please help with what I have done wrong , added code in reply section

time takeen , 2 minutes for my business logic without multithreading

after implementing multithreading and below code time was same, it should reduce because I have added 10 run time tasks.

  • Sachin Mittal Profile Picture
    Sachin Mittal 490 on at
    Implemented Multithreading using run base batch , but batch run time is not decreasing !! help
    yes, I understand that, but I have implemented my same logic using sysoperation framework, that is working absolutely fine (multiple tasks gets created, also batch time reduced to 12 sec from 3 minutes , adding Sc too ) I don't understand why run base is not working
  • Balbir Singh Profile Picture
    Balbir Singh 5 on at
    Implemented Multithreading using run base batch , but batch run time is not decreasing !! help
    Assuming that threads are created correctly. One factor that can affect the performance of your batch job is the number of threads . Sometimes, your batch job tasks may have to wait for other batch jobs that are running at the same time, which can make it take longer to finish. To test this, you can try disabling other batch jobs and see if your batch job runs faster. When you configure your batch job in the Production environment, you can also use the Priority based scheduling option to reduce the waiting time for your batch job tasks.
     
     
     
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    Implemented Multithreading using run base batch , but batch run time is not decreasing !! help
    This seems to be a duplicate of your other thread, How implement multi-threading using SysOperation framework. There you also talked about 25 fields, which is useless information, and told us nothing about what actions you run in parallel.
     
    Starting the same discussion again from scratch is a waste of time. Instead, you need to give us better information.

    If you use multithreading in a wrong way, you may indeed get no benefit or even worse performance (because of an overhead).
  • Sachin Mittal Profile Picture
    Sachin Mittal 490 on at
    Implemented Multithreading using run base batch , but batch run time is not decreasing !! help
    for demonstration purposes (to implement multithreading), in demobusinesslogic class, I have added 25 fields in sales table of type string, assigned some values to all these fields. 
    so running batch job will fill values in all 25 fields.
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,253 Super User 2024 Season 2 on at
    Implemented Multithreading using run base batch , but batch run time is not decreasing !! help
    Hi Sachin,
     
    Can you tell what exactly the batch job should do? When using multiple threads, depending on the circumstances, it won't be faster. If you have a few records to process, a single thread could be faster. In case there are locks on several tables, the multi-thread might make things worse. 
     
    Using a single or multiple threads should be part of the design with a careful decision. I would suggest using the Trace parser tool to find out what exact coding or database calls are causing a delay. Then you can find out what to improve. We don't know what exactly is being executed in your DemoBusinessLogic class.
  • Sachin Mittal Profile Picture
    Sachin Mittal 490 on at
    Implemented Multithreading using run base batch , but batch run time is not decreasing !! help
    class MultiThreadRunBaseBatch extends RunBaseBatch
    {
        #define.CurrentVersion(1)
        #localmacro.CurrentList
            salesTableBuffer
        #endmacro
     
        SalesTable          salesTableBuffer;

        public boolean canGoBatchJournal()
        {
            return true;
        }

        protected boolean canRunInNewSession()
        {
            return true;
        }

        public boolean runsImpersonated()
        {
            return true;
        }
     
        public container pack()
        {
            return [#CurrentVersion, #CurrentList];
        }

        public boolean unpack(container packedClass)
        {
            Version version = runbase::getVersion(packedClass);
            switch (version)
            {
                case #CurrentVersion:
                    [version, #CurrentList] = packedClass;
                    break;
                default:
                    return false;
            }
            return true;
        }

        static ClassDescription description()
        {
            return 'MultiThreading RunBaseBatch FrameWork';
        }

        server static MultiThreadRunBaseBatch construct()
        {
            return new MultiThreadRunBaseBatch();
        }

        static void main(Args args)
        {
            MultiThreadRunBaseBatch   multiThread;
            multiThread = MultiThreadRunBaseBatch::construct();
            if (multiThread.prompt())
            {
                multiThread.run();
            }
        }
       
        public void pramSalesBuffer(SalesTable _sales)
        {
            salesTableBuffer=_sales;
        }

        public void run()
        {
            try
            {
                DemoBusinessLogic demoBusinessLogic = new DemoBusinessLogic();
                demoBusinessLogic.UpdateData(salesTableBuffer);
            }
            catch
            {
                info(strFmt("%1",xSession::xppCallStack()));
            }
        }
    }
  • Sachin Mittal Profile Picture
    Sachin Mittal 490 on at
    Implemented Multithreading using run base batch , but batch run time is not decreasing !! help
    class MultiThreadRunBaseTask extends RunBaseBatch 
    //using this class to add runtime tasks , and on action menu item
    {
        BatchHeader batchHeader;
            SalesTable                          j;

        public static void main(Args args)
        {
            MultiThreadRunBaseTask  objMultiThread = new MultiThreadRunBaseTask();
            if (objMultiThread.prompt())
            {
                objMultiThread.run();
            }
        }
        void run()
        {
            MultiThreadRunBaseBatch             multiThreadRunBaseBatch;
            try
            {
                while select firstonly10 j
                {
                    if(this.isInBatch())
                    {
                        if(!batchHeader)
                        {
                            batchHeader = BatchHeader::construct(this.parmCurrentBatch().BatchJobId);
                        }
                        batchHeader.parmCaption("Multiple thread batch jobs");
                        MultiThreadRunBaseBatch =  new MultiThreadRunBaseBatch();
                        MultiThreadRunBaseBatch.pramSalesBuffer(j.data());
                        batchHeader.addRuntimeTask(MultiThreadRunBaseBatch, this.parmCurrentBatch().RecId);
                    }
                    else
                    {
                        // execute your code here when not running in batch
                    }
                }
                if(batchHeader)
                {
                    batchHeader.save();
                }
            }
            catch
            {
                info(strFmt("%1",xSession::xppCallStack()));
            }
        }
        public container pack()
        {
            return conNull();
        }
        public boolean unpack(container packedClass)
        {
            return true;
        }
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans