我想创建1000万客户进行性能测试。我正在运行一个基本的groovy脚本来创建一个只有强制属性的客户。然后我在循环中运行脚本。 如何提高这个groovy脚本的性能? 我找不到impex导入中可用的相应多线程选项。 有没有更好的方法在Hybris创造1000万客户?
用于生成具有不同id的客户的示例groovy脚本。
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())
}
}
我会说逻辑上的答案是使用Impex文件。这允许创建批量并支持多线程:https://help.hybris.com/1811/hcd/44f79c4e604a4bff8456a852e617d261.html
基本上你可以配置工人或线程的数量:
impex.import.workers=4
您将负责将输入格式转换为* .csv或* .impex
另外:关于Groovy脚本,您可以使用impex设置uid和名称,只需要提前提供随机数。您可以在Excel或某种脚本语言中执行此操作。
你甚至可以通过代码执行在impex本身中完成它。
但是如果你只是想要很多随机客户:你也可以用/ hac启动10个浏览器窗口并运行脚本十次。
我用上面的groovy脚本创建了多个ScriptingJob
并将它们附加到30个不同的Cronjobs
。并行执行所有这些都可以获得相同的结果。