在我的毕业论文中,我开发了用于在客户端和数据库之间进行选择/保存操作的REST API。数据将作为JSON从传感器发布并存储在MongoDB中。我们选择了三种不同的存储技术:Jongo驱动程序1.3.0,Java MongoDB驱动程序3.4.0和Spring的MongoRepository(带有Jackson FasterXML)。在实现之后,我们通过JMeter开始进行负载测试。测试用例有这些参数:通过Jongo驱动程序,Java MongoDB驱动程序和MongoRepository之间的负载测试比较保存方法
线程 - 100,250,500,1000
斜坡上升期 - 10秒
循环计数 - 30
我们假设司机会更有效而不是MongoRepository,但是在1000个线程的情况下,MongoRepository每秒加载400个请求,驱动程序无法处理所有的请求。所以MongoRepository可以快速存储。任何人都可以说为什么MongoRepository更有效?
编辑:
MongoRepository是这样的:
@Repository
public interface EndPointsMongoRepository extends
MongoRepository<EndPointsDataControllerEntity, String> {
}
方法deseralize JSON到实体:
private EndPointsDataControllerEntity parseDataFromJson(String json) {
ObjectMapper mapper = new ObjectMapper();
EndPointsDataControllerEntity controller = null;
try {
controller = mapper.readValue(json, EndPointsDataControllerEntity.class);
} catch(JsonParseException ex){
LOGGER.warn(" JsonParseException with message :" + ex.getMessage());
} catch(JsonMappingException ex){
LOGGER.warn("JsonMappingException with message :" + ex.getMessage());
} catch(IOException ex){
LOGGER.warn("IOException with message :" + ex.getMessage());
}
LOGGER.info("Id controller: " + controller.getIdController());
return controller;
}
然后我只保存数据。
的MongoDB的Java驱动程序实现:
public void saveUnstructuredMeasuredData(String json) {
LOGGER.info("Data saved to database by second way: \n" + json);
com.mongodb.client.MongoCollection<Document> collection = getMongoClient().getCollection(UNSTRUCTURED_DATA);
Document objectFromJson = Document.parse(json);
objectFromJson.put(TIMESTAMP_MEASURE, createTimeMeasureAsTimestamp(objectFromJson));
collection.insertOne(objectFromJson);
}
而且Jongo:
public void saveUnstructuredMeasuredDataStraightWithShell(String json) {
LOGGER.info("Data saved to database by third way: \n" + json);
Jongo jongo = new Jongo(getMongoDB());
MongoCollection measuredData = jongo.getCollection(MEASURED_DATA);
measuredData.insert(json);
}
我明白Jongo喜欢“官方”java驱动程序的扩展,我得到的结果有一点点更好的性能。 –