In my diploma thesis I developed REST API for select/save operations between client and database. Data will be post from sensors as JSON and stored in MongoDB . We chose three different technologies for storing: Jongo driver 1.3.0, Java MongoDB driver 3.4.0 and MongoRepository from Spring (with Jackson FasterXML). After implemenetation we started with load tests through JMeter. Test case had these parameters:
threads - 100, 250, 500, 1000
ramp up period - 10 seconds
loop count - 30
We are supposed that drivers will be more effective than MongoRepository, but in case of 1000 threads MongoRepository load 400 requests per second and drivers could not process all of requests. So MongoRepository can store rapidly fast. Can anyone says why MongoRepository is more effective ?
EDIT:
MongoRepository look like this:
@Repository
public interface EndPointsMongoRepository extends
MongoRepository<EndPointsDataControllerEntity, String> {
}
Method deseralize json to entity :
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;
}
Then I only save data.
Java MongoDB driver implementation:
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);
}
And 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);
}