Search code examples
multithreadingperformancegroovyperformance-testingsap-commerce-cloud

How to implement multithreading in groovy?


I want to create 10 million customers for performance testing. I am running a basic groovy script for creating a customer with only mandatory attributes. Then I am running the script inside a loop.
How can I improve the performance of this groovy script?
I can't find the corresponding multi-threading options that are available in impex import.

Is there a better way of creating 10 million customers in Hybris?

Edit 1:

Sample groovy script for generating customers with different id's.

    import com.google.common.collect.ImmutableSet
    import de.hybris.platform.core.model.user.AddressModel
    import de.hybris.platform.core.model.user.CustomerModel

    //Setting only mandatory attributes
    for(int i=0; i<100000; i++) {
        customerModel = new CustomerModel()
        id = new Random().nextInt(100000000)
        uid = 'TestCustomer_'+id
        customerModel.setUid(uid)
        name = 'Test Customer Name_'+id
        customerModel.setName(name)

        addressModel = new AddressModel()
        addressModel.setOwner(customerModel)
        customerModel.setDefaultPaymentAddress(addressModel)
        customerModel.setDefaultShipmentAddress(addressModel)

        try{
        modelService.save(customerModel)
        }catch(Exception e){
        println('Creation of customer with id = '+uid+' and amway account = '+code+' failed with error : '+e.getMessage())
        }
    }

Solution

  • I created multiple ScriptingJob with the above groovy script and attached them to 30 different Cronjobs. Executing all of them in parallel achieved the same result.