Posts Tagged ‘mongodb’

Post

Running MongoDB Completely in RAM

In sysadmin on August 11, 2011 by Wenzi Tagged: , ,

The project I am working on runs test cases constantly ( and you should too ) that are constantly creating and destroying MongooDB databases.

All those database allocations ( Mongo allocating the datafile ) was taking a lot of time on this not small project.

So with a need for speed, we put the database in RAM. This is how, if you need more speed , you can run Mongo completely in RAM.

/home/me# mkfs -q /dev/ram1 32768
/home/me# mkdir -p /ramcache
/home/me# mount /dev/ram1 /ramcache

[1] Make a filesystem in ram. mkfs makes a /dev in ram of the specified size. In this case 32M ( 32768 ), but you will have to make a bigger one for mongo, greater than 192M.

[2] Make a mount point. We need a directory to ‘attach’ the ram filesystyem so normal applications can access it as part of the file system.

[3] Mount the drive. Mount the ram drive on the mount point you just made.

To test it, we run mongodb with the ramcach as the datapath.

mongod –dbpath /ramcache/ –port 29019

 

Looking at the directory from another terminal window ( or tmux ) we can see that the lock file was created.

me@li132-23:~$ ls -la /ramcache/
total 18
drwxrwxrwx 3 root root 1024 Aug 11 04:36 .
drwxr-xr-x 22 root root 4096 Aug 11 04:31 ..
drwx------ 2 root root 12288 Aug 11 04:30 lost+found
-rwxr-xr-x 1 me me 6 Aug 11 04:37 mongod.lock

Now we can connect to the mongo server.

mongo --host localhost:29019

Now it just acts like a regular server, because it is, just running in RAM.

> use wenzi
switched to db wenzi
> doc = { author : 'wenzi', post : 'Water : the new Coke' }
> db.posts.insert(doc);

Comments Off

Post

Rotating MongoDB Log Files with Logrotate

In sysadmin on August 3, 2011 by Wenzi Tagged: , , , , ,

Rotating log files is something sys admins are all familiar with doing. There are a few ways to backup MongoDB, with the most common are the logRotate command and logrotate.

I prefer runCommand(“logRotate”) to rotate my log files. I administer a couple of MongoDB instalations and I check on them every day, and for those I prefer rotating them manually.

I do still have a mongoDB that is my little orphan server that runs logrotate. It just runs and I check on it every few weeks. For this one I use log rotate to make sure my disks do not fill up.

But theare are some people who prefer using logroatate, just because they are old school. I am one of those for everything but mongo.

So if you are used to logrotate, here is a script for you. You will have to change the parts for your own setup of course.

This server only ones one mongod ( yes, bad but this is not a critial machine ). If you are running more than one instnce the you will have to make changes obviously.

Place this in the file /etc/logrotate.d/mongodb

/var/log/mongodb/*.log {
	rotate 52
	size 50M
	compress
	weekly
	dateext
	missingok
	notifempty
	sharedscripts
	postrotate
		/bin/kill -SIGUSR1 `cat /var/lib/mongo/mongod.lock 2> /dev/null` 2> /dev/null || true
	endscript
}

Cheers

Comments Off

Post

Mongo Clusters are Like Driving a Big Boat

In Uncategorized on July 28, 2011 by Wenzi Tagged: , ,

Mongo Clusters are Like Driving a Big Boat.

CLUSTERS CAN BE BIG

The things about clusters, any clusters, is that a lot of things go any to do anything. That is the nature of clusters. They are like turning a big boat in the ocean as compared to a jet ski.

A change is communicated among the nodes in a cluster, passing through different servers. Now the smaller the cluster, the less things have to talk to each other.

A cluster of one ( as in a single machine ) is instantaneous. A cluster of a thousand may take a lot more time for what ever you are doing to propagate through the cluster.

This brings us to mongo. When you are dealing with a cluster , it is a conversation. You tell / ask a mongo cluster to do something, and it goes off and does it. It will let you know when it is done.

SHARDING AGAIN

Think about a sharding mongo DB cluster. You make a change it will take time for whatever you are doing.

Your change may cause the balancer to start moving data from shard to shard, or refreshing a stale node or whatever.

There are tons of things that a mongo cluster could be doing when you issue commands. So here is the takeaway

Let mongo take it’s time and do what it is going to do

if you issue a command to a mongo cluster, realize that it will take time to complete. Let mongo DB do what it is going to do. It may take time, but something is probably happening and jumping to conclusions will not help.

Comments Off

Post

MongoDB is the new MySql

In Uncategorized on July 24, 2011 by Wenzi Tagged: ,

I think this article is a little biased, but he is a Red Sox fan and you know how they are.

MongoDB is the new MySql

Comments Off

Post

MongoDB : Making a Specific Node Primary in a Replica Set

In sysadmin on July 24, 2011 by Wenzi Tagged: , , , ,

MongoDB is funny in that you are having a conversation with the cluster than sending commands.

Making a PARTICULAR machine primary is one of those times. Now I will separate the blog into three parts. Pre  Mongo 1.7.2, Mongo 1.7.2 to Mongo 1.9.1 and after Mongo 1.9.1

PRE MONGO 1.7.2

I have no idea, never tried it. If you are still using a pre 1.7.2 version, stop it. Unless you have some reason for sticking to an old version, just move to a newer version.

MONGO 1.7.2 to MONGO 1.9.1

Mongo 1.7.2 introduced ReplFreeze. That is the ability to stop a machine from becoming primary for a certain period of time. For example,

rs.freeze(120)

would stop the node from becoming the primary server for 120 seconds.

You would freeze all the nodes you did not want to become primary and then tell the current primary to step down as primary.  A new election would be held, and all the frozen nodes would decline to be elected to be primary, leaving the one you did not freeze to be primary.

POST MONGO 1.9.1

This is the easiest case. 1.9.1 introduced a variable priority.

You would set the priority of the server you want to become primary higher. If the server you want to become primary is within 10 seconds of the current primary, the current primary will step-down. If it is too far behind, an election would be held when it came within 10 seconds. Or if you cannot wait, you could force the primary to step  down.

db.adminCommand({replSetStepDown:1000000, force:1})

You will be primary less until the higher priority node catches up.

Comments Off