2017-04-10 65 views
0

在我的畢業論文中,我開發了用於在客戶端和數據庫之間進行選擇/保存操作的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); 
} 

回答

0

Jongo是不是一個驅動程序,它使用一個。 基本上,你接下來提到的那個 - 那就是「官方」司機。 第三個甚至是界面,有兩個不同的實現 - 哪一個是你的?

所以,看,你剛剛創建了一種概念上的混亂。爲了回答您的問題,您需要了解每個案例的實施細節。

我可以假設,作爲企業級和相當成熟的框架,Spring有更有效率的併發實現,有連接/工作池或類似的東西。

+0

我明白Jongo喜歡「官方」java驅動程序的擴展,我得到的結果有一點點更好的性能。 –