I wanted to migrate our servers today, but I couldn't since on the new (larger) server MongoDB was very slow for a specific collection. First of all, here are the specs.
Old server:
Digital Ocean 80$ Instance
RAM: 4GB
vCPUs: 4 (I can't find the GHZ)
New server:
Switch Engines c1.large Instance
RAM: 8GB
vCPUs: 8 (again, I can't find the GHZ)
Both servers have enough SSD space.
while I'm retrieving documents from this one specific collection. Afterwards still the mongodb keeps the 43% memory occupied. On the old server, mongo uses constantly around 8% memory and there are no CPU spikes when I request documents from the problematic collection.
What I'm doing to retrieve the things from the collection is:
Iterator<CompilerCacheEntry> found = ds()
.find(CompilerCacheEntry.class).filter("hash", hash)
while (found.hasNext()) {...
where ds
is from org.mongodb.morphia.Datastore;
and the filter is implemented like this:
public Query<T> filter(String condition, Object value) {
String[] parts = condition.trim().split(" ");
if(parts.length >= 1 && parts.length <= 6) {
String prop = parts[0].trim();
FilterOperator op = parts.length == 2?this.translate(parts[1]):FilterOperator.EQUAL;
this.add(new Criteria[]{new FieldCriteria(this, prop, op, value, this.validateName, this.validateType)});
return this;
} else {
throw new IllegalArgumentException("\'" + condition + "\' is not a legal filter condition");
}
}
What's also curious, is that the mongodb before migration was 30GB and now it's 3GB, but I read that's just because mongo cleans up upon migration.
So I'm left with general confusion and some questions:
- How can it be, that on the stronger machine mongo is slower?
- Why is mongo hogging 43% memory?
- It looks like mongo is only using one cpu, might this be the problem?
- Is the problem memory related or cpu related or none of those?
- What's the problem with mongo, respectively my code? Why does mongo have such a hard time retrieving this object?
- Is my collection too large for my memory?
Here are parts of the collection stats for reference:
>db.compilercache.stats()
{
"ns" : "taskbase.compilercache",
"count" : 21191,
"size" : 4592895563,
"avgObjSize" : 216738,
"storageSize" : 1814052864,
"capped" : false,
In case you need more information, please let me know. Thanks a lot in advance!