I found my MongoDB remove data is very slow, but query or insert action is ok.
This is my shard status:
shards:
{ "_id" : "shard0000", "host" : "192.168.1.50:27017", "tags" : [ "global" ] }
{ "_id" : "shard0001", "host" : "192.168.2.50:27017", "tags" : [ "china" ] }
The two databases are setup in different countries. But I'm sure I put all data to the same database in my test.
This is the record structure:
{
"_id": ObjectId("56cd5cdae4b0323bc94339e6"),
"eventId": NumberLong(5680),
"opuId": NumberLong(2576),
"eventTime": ISODate("2016-02-24T07:33:46.471Z")},
{
"_id": ObjectId("56cd5cdae4b0323bc94339e7"),
"eventId": NumberLong(5681),
"opuId": NumberLong(2576),
"eventTime": ISODate("2016-02-24T07:34:46.471Z")}
I use spring framework and here is my code:
Query:
@Query(value = "{'eventId' : ?1}")
public Event findByEventId(long eventId);
Delete:
mongoTemplate.remove(query(where("eventId").is(event.getEventId())), Event.class);
Generally, saving or querying 100 records would spend 100ms. But removing 100 records case by case takes over 30 seconds.
But if I use batch delete, it spend less then 50ms. It looks normally.
mongoTemplate.remove(query(where("opuId").is(opuId)), Event.class);