moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 513 forks source link

Constant load on pubsubCollection in mongodb #784

Open einarnot opened 5 years ago

einarnot commented 5 years ago

Im running my mosca node js server on a raspberry pi zero, so resources are limited. I noticed using top that mongodb always use about 20% CPU, even when there is no messages sent over MQTT. When I run mongotop, I see that its the pubsubcollection that always has about 25ms of read activity.

Is there anyway to avoid the constant load on the pubsubcollection in mongodb?

Here are my settings:

var pubsubsettings = {
  type: 'mongo',               
  url: 'mongodb://localhost:27017/mqttdashboard',
  pubsubCollection: 'MqttPubSubCollection',
  mongo: {}
};

var moscaSettings = {
  port: 1883,         
  backend: pubsubsettings,
  persistence: {
   factory: mosca.persistence.Memory
  }
};
ibrahim-sakr commented 5 years ago

it will be better to have a way to inject an existing mongo Connection as we have in attachHttpServer() so if we can make something like attachMongoConnection()