I have encounter an issue where I run some query and also the mysqld process begins using 100% CPU energy, without ending. I wish to pinpoint this question. However , log/development.log consists of only queries which have finished. Any idea?

I believe you've got a couple of choices for this. The very first is really considering your development.log to see which actions are leading to it. Have a look in the queries you are asking rails to operate and then try to pinpoint that specific query. Whether it's taking a lot of time that it most likely means you are doing something similar to coming back n+1 queries, missing indexes as well as other performance killer.

You state that the dev log has only queries which have finished. Can't you're employed out exactly what the next query to operate could be?

Your other available choices involve beginning mysqld having a log (i believe what they are called of a few of these have transformed):

mysqld --log[=file_name] --log-slow-queries[=file_name]

Showing the present statement list using processlist from inside mysql:

show processlist;

To avoid that happening again you might take a while to check out a rails performance monitor like Revoltions per minute from New Relic (http://www.newrelic.com/).

I really hope this can help!

You can have a look at running/incomplete claims through the

show processlist;


For those who have assess to MySQL, think about the SQL query


Or in the command line:

mysqladmin processlist

Alternatively, probably the most effective strategy is to override the 'execute' approach to the ActiveRecord::Base connection instance. This short article shows the overall approach:


You place this code into application.rb:


connection = ActiveRecord::Base.connection
class << connection
    alias :original_exec :execute
    def execute(sql, *name)
        # try to log sql command but ignore any errors that occur in this block
        # we log before executing, in case the execution raises an error
            lines = if File::exists?(SQL_LOG_FILE) then IO::readlines(SQL_LOG_FILE) else [] end
            log = File.new(SQL_LOG_FILE, "w+")
            # keep the log to specified max lines
            if lines.length > SQL_LOG_MAX_LINES
            lines << Time.now.strftime("%x %I:%M:%S %p")+": "+sql+"n"
            $sql_log = sql
        rescue Exception => e
        # execute original statement
        original_exec(sql, *name)
    end # def execute
end # class <<