我正在使用带有Spring Data的MongoDB来创建我们的原型应用程序。保存操作非常快,但是为了列出结果,性能非常差,即使它们只有3到4个记录持续存在。另一个令人惊讶的部分是每次连续列表操作都会导致性能下降。
在这里给出一个想法是单个json,它不是世界上最大的。
{
"enquiryId": "574feac25215eae3e2e1434b",
"enquiryName": "Mineral Shipment",
"dateOfEnquiry": null,
"requiredFrom": 1465324200000,
"requiredTo": 1483036200000,
"source": {
"locationId": null,
"area": {
"pincode": null,
"area": null,
"city": {
"cityId": null,
"cityName": "Panjim",
"state": {
"stateId": null,
"stateName": " Goa 403001",
"country": {
"countryId": null,
"countryName": " India"
}
}
}
}
},
"destination": {
"locationId": null,
"area": {
"pincode": null,
"area": null,
"city": {
"cityId": null,
"cityName": "Ludhiana",
"state": {
"stateId": null,
"stateName": " Punjab 141001",
"country": {
"countryId": null,
"countryName": " India"
}
}
}
}
},
"shipment": {
"shipmentId": null,
"enquiryId": null,
"shipmentName": "Mineral Shipment",
"valueOfGoods": null,
"categories": [
{
"categoryId": null,
"categoryName": "Hazardous,Flammable",
"subCategories": null,
"shipmentId": null
}
],
"modes": [
{
"modeId": null,
"modeName": "WATER",
"modeDescription": null,
"shipmentId": null
}
],
"items": [
{
"itemId": null,
"itemName": "Coal",
"shape": null,
"form": null,
"dimension": null,
"weight": null,
"quantity": null,
"shipmentId": null
},
{
"itemId": null,
"itemName": "Nickel",
"shape": null,
"form": null,
"dimension": null,
"weight": null,
"quantity": null,
"shipmentId": null
}
]
},
"transportEnquiries": [
{
"transportEnquiryId": null,
"transport": {
"transportId": null,
"name": "Flat Bed",
"mode": {
"modeId": null,
"modeName": "WATER",
"modeDescription": "The two world wars gave a great impetus to the development of air transport in almost all the countries of the world",
"shipmentId": null
},
"type": {
"typeId": null,
"name": "LWH",
"modeId": null,
"illustrationURL": null
},
"desc": "Description of Flat Bed"
}
}
],
"storageEnquiries": [],
"packagingEnquiries": null,
"insuranceEnquiries": null,
"documentationEnquiry": null,
"trackingToolRequired": null,
"customerSupportRequired": null,
"insuranceRequired": null,
"storageRequired": null,
"documentationRequired": null,
"published": false,
"userId": null
}
这是Spring Service
public class EnquiryManagementService implements IEnquiryManagementService{
@Autowired
private EnquiryRepository enquiryRepository;
public Enquiry createEnquiry(Enquiry enquiry) {
Enquiry enquiryObj = (Enquiry)enquiry;
Enquiry e = enquiryRepository.save(enquiryObj);
return e;
}
@Override
public List<Enquiry> listEnquiry(int start) {
long startTime = System.currentTimeMillis();
Page<Enquiry> enquiries = enquiryRepository.findAll(new PageRequest(start,10));
long endTime = System.currentTimeMillis();
System.out.println("Time Taken = "+(endTime-startTime));
return enquiries.getContent();
}
}
以下是在不添加任何记录的情况下连续4次处理findAll()所花费的时间的结果。系统中只有4条记录,您可以看到所用时间分别为10.7秒,25.7秒,41.9秒和58.5秒。每个请求都需要一辈子的时间才能完成。
以下是我的系统的配置 - 英特尔酷睿i3 2330M @ 2.2 GHz - 2 GB RAM - 64位Windows 7 - 我系统本地安装的MongoDB版本:3.2 - 执行此查询时CPU利用率为50%,内存为80%
理想情况下,此操作必须在不到半秒或最多一秒钟内完成。任何形式的帮助都会很棒。