500 error when executing lots of sqls.

Discussion in 'Ruby/Rails' started by dlhhyct, Sep 17, 2006.

  1. dlhhyct

    dlhhyct New Member

    • under lsws and ruby lsapi, I often get "The size of dynamic response header is over the limit." warning msg when page or controller method contains large amount of sql calls. lsws aborts the request, and lsws returns 500 server error in browser.
    • although all sqls are executed, and controller method completes successfully, browser just returns 500 error anyway.
    • In admin GUI, After I change tuning/Max Dynamic Response Header Size (bytes) to 8192, instead of 500 error, browser ask me to download the page, I guess for debugging purpose, file (1-2 kb) I download starts with one sql statement and follows with binary stuff. Download only happens in rails development mode, production mode always returns 500 error regardless header size.
    • Same code works under webrick.
    • I know header size is for security/ddos reasons, why does it go off when I do lots of sqls?

    how do I avoid this error when I have to do lots of sql calls?

    test code below, try raise or lower the number to see different behaviors.
    Code:
    class TestController < ApplicationController
      def index
        70.times{|i|   
          begin
            logger.info(i)
            user = User.find(i)
          rescue Exception => err   # rails throw err if no user found
            logger.error(err)
          end
        }
      end
    end
  2. dlhhyct

    dlhhyct New Member

    hold on

    spoke too soon, I create a whole new app, and was unable to reproduce 500 error, i guess cause is somewhere else in my current app. :(

    please disregard my previous post.
  3. mistwang

    mistwang LiteSpeed Staff

    Maybe your rails app uses a lot of memory for those SQL, try increasing the "memory limit" under "Rails" tab, see if it helps or not.

    You should be able to find some clues for this problem in lsws/logs/stderr.log, lsws/logs/error.log as well as Rails' log files.
  4. dlhhyct

    dlhhyct New Member

    solved

    in my code, i had lots of puts statements to debug, and i even overwrite logger.debug in model classes, because debug msg wasn't showing somehow before. after i remove all of these puts. problem went away.

    Code:
    def logger.debug(msg)
      puts msg
    end
    
    I guess when lots of sql is being called, all these puts accumulates and exceed header limit.

Share This Page