• Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    Python
  • Created about 13 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Painless profiling for MongoDB

Professor

Professor is a web application with corresponding command-line tool to read, summarize, and interpret MongoDB profiler output (for MongoDB 2.0 and later).

Installing

Professor requires MongoDB, Python, Flask, WTForms, and PyTZ. These can all be installed by running:

python setup.py [install|develop]

This will install the required dependencies, as well as the profess command-line script. You can then run Professor locally on port 8080 with:

python server.py

If you want Professor to store its database in a MongoDB instance other than on the default port on localhost, edit professor.cfg or create a new file private.cfg and set the appropriate values in the MONGODB_CONFIG variable.

Set up your databases

Once Professor is installed and running, go to http://localhost:8080/ in your browser, and click "New Database" in the upper-right corner. Enter the hostname, database name, and optionally username and password (if you are using database authentication), then click Submit.

This will take you to the main page for your database, but it won't yet have any information to display. You must update Professor from time to time, by clicking the "update now" link, or using the command-line tool (preferred).

Updating profiling data

The best way to update the profiling data is to ask the profess script to periodically query for new profiling information from the target databases:

profess -s 5 update localhost/example localhost/test

will update the "example" and "test" databases running on localhost every 5 seconds.

How Professor Works

Professor is designed to have minimal impact on running systems. It connects to target databases each time an update is issued (through the web or command line), queries only for new data in system.profile since the last update, and replicates that data to its own database for use from within the Professor webapp. In instances where you do not wish to impact your running databases any more than is absolutely necessary (i.e. production databases), Professor should be configured to use its own instance of MongoDB running on separate hardware.

While querying for profile information, Professor annotates the profile entries with a few useful pieces of additional information:

  • A query "skeleton," which is a string representation of the structure of the query; that is, it shows which keys were present, but no values set for those keys. This enables Professor to group queries with the same structure together for reporting.
  • A sort "skeleton," if the query included a sort().

The skeleton is a simple transformation of a BSON document into a string as follows:

  • For (embedded) documents, order the keys and recurse; emit keys separated by commas and surrounded by { and }; when recursion returns a sub-skeleton, separate the key and value with a colon
  • For arrays, iterate in order and recurse; emit recursed contents separated by commans and surrounded by [ and ]
  • For everything else, emit nothing

Thus a query such as:

{username: "dcrosta", city: "New York", zip: {$in: [10010, 10011]}}

Has as its skeleton:

"{city,username,zip:{$in:[]}}"

Note that, although the order of keys is not preserved, it is predictable (since the keys of documents are sorted alphabetically).

Professor at the command line

The profess command line tool has a number of modes of operation:

  • list will show you all the configured databsaes in your Professor instance
  • update will allow you to update Professor's cached copy of profiling data for one or more databases
  • clean will erase Professor's cached profiling data, but not reset the timestamp (so that only new profiling data will be collected by update)
  • reset will perform a clean and also reset the timestamp, so that the next call to update will re-cache all existing profiling data
  • remove will remove a database from your Professor instance

Full usage is available in the profess tool with profess -h or profess [command] -h for any of the above commands.

About

Professor is by Dan Crosta. It is BSD-licensed, and feedback and contributions are encouraged. I hope you find it useful!

More Repositories

1

flask-pymongo

PyMongo support for Flask applications
Python
707
star
2

plog

A blog using Flask, Mongoengine, and MongoDB, as see on late.am
Python
36
star
3

keystone

A very simple, yet flexible, dynamic website framework
Python
27
star
4

dabble

Simple A/B testing framework for Python
Python
27
star
5

xrange

A pure-Python implementation of the xrange builtin
Python
17
star
6

flask-tweepy

Python
9
star
7

cookbook-preferred

Chef LWRP to dynamically set attributes.
Ruby
8
star
8

vienna-rss

Vienna is a freeware, open source RSS/Atom newsreader for the Mac OS X operating system.
C
6
star
9

nymwit

Nymwit is a word game in which players compete to come up with the most creative, popular, quirky, or notable acronym given a set of letters
Python
4
star
10

dtk

DTK is a curses 'GUI' toolkit for python programs
Python
4
star
11

browsershame

Web browsers use too many resources -- shame on you!
Python
3
star
12

wideload

C
3
star
13

delayserver

Threaded TCP echo server with customizable response latency
C
3
star
14

python-questions

Python
2
star
15

cookbook-disco

Chef Cookbook to install the Disco map-reduce framework
Ruby
2
star
16

sendlib

sendlib is a lightweight message serialization library, written in Python
Python
2
star
17

pymongodump

utility to dump and restore mongodb databases from python (with pymongo)
Python
2
star
18

revised

Automatic revision control for your Django models
2
star
19

keystone-heroku-demo

Hello/Howdy/Hiya, world! in Keystone
Python
2
star
20

shmdict

Python
1
star
21

cacheorbust

Read-behind HTTP API cache with memcached protocol support
C++
1
star
22

eventbrite

Client for Eventbrite's HTTP-based API
Python
1
star
23

simplest-python-project

Python
1
star
24

synk

Application event synchronization service with HTTP/JSON API
Python
1
star
25

shrt

A little URL shortener with Python, Flask, and MongoDB
Python
1
star