AppController/djinn.rb
# Updates internal state about the number of requests seen for the given App
# Engine app, as well as how many requests are currently enqueued for it.
# Some of this information is also sent to the AppDashboard for viewing by
# users.
#
# Args:
#   app_name: A String that indicates the name this Google App Engine
#     application is registered as.
#   total_requests_seen: An Integer that indicates how many requests haproxy
#     has received for the given application since we reloaded it (which
#     occurs when we start the app or add/remove AppServers).
#   time_requests_were_seen: An Integer that represents the epoch time when we
#     got request info from haproxy.
#   total_req_in_queue: An Integer that represents the current number of
#     requests waiting to be served.
#   update_dashboard: A boolean to indicate if we send the information
#     to the dashboard.
Updates internal state about the number of requests seen for the given App
Engine app, as well as how many requests are currently enqueued for it.
Some of this information is also sent to the AppDashboard for viewing by
users.

A String that indicates the name this Google App Engine
application is registered as.
total_requests_seen: An Integer that indicates how many requests haproxy
has received for the given application since we reloaded it (which
occurs when we start the app or add/remove AppServers).
time_requests_were_seen: An Integer that represents the epoch time when we
got request info from haproxy.
total_req_in_queue: An Integer that represents the current number of
requests waiting to be served.
update_dashboard: A boolean to indicate if we send the information
to the dashboard.
Updates internal state about the number of requests seen for the given App Engine app as well as how many requests are currently enqueued for it . Some of this information is also sent to the AppDashboard for viewing by users . A String that indicates the name this Google App Engine application is registered as . total_requests_seen : An Integer that indicates how many requests haproxy has received for the given application since we reloaded it ( which occurs when we start the app or add / remove AppServers ) . time_requests_were_seen : An Integer that represents the epoch time when we got request info from haproxy . total_req_in_queue : An Integer that represents the current number of requests waiting to be served . update_dashboard : A boolean to indicate if we send the information to the dashboard .
def update_request_info(app_name, total_requests_seen,
    time_requests_were_seen, total_req_in_queue,  update_dashboard)
    Djinn.log_debug("Time now is #{time_requests_were_seen}, last " +
      "time was #{@last_sampling_time[app_name]}")
    Djinn.log_debug("Total requests seen now is #{total_requests_seen}, last " +
      "time was #{@total_req_rate[app_name]}")
    Djinn.log_debug("Requests currently in the queue #{total_req_in_queue}")
    requests_since_last_sampling = total_requests_seen - @total_req_rate[app_name]
    time_since_last_sampling = time_requests_were_seen - @last_sampling_time[app_name]
    if time_since_last_sampling.zero?
      time_since_last_sampling = 1
    end
    average_request_rate = Float(requests_since_last_sampling) / Float(time_since_last_sampling)
    if average_request_rate < 0
      Djinn.log_info("Saw negative request rate for app #{app_name}, so " +
        "resetting our haproxy stats for this app.")
      initialize_scaling_info_for_app(app_name, true)
      return
    end
    if update_dashboard
      send_request_info_to_dashboard(app_name, time_requests_were_seen,
        average_request_rate)
    end
    Djinn.log_debug("Total requests will be set to #{total_requests_seen} " +
      "for app #{app_name}, with last sampling time #{time_requests_were_seen}")
    @current_req_rate[app_name] = total_req_in_queue
    @total_req_rate[app_name] = total_requests_seen
    @last_sampling_time[app_name] = time_requests_were_seen
  end
def update_request_info ( app_name , total_requests_seen , time_requests_were_seen , total_req_in_queue , update_dashboard ) Djinn . log_debug ( "Time now is #{time_requests_were_seen}, last " + "time was #{@last_sampling_time[app_name]}" ) Djinn . log_debug ( "Total requests seen now is #{total_requests_seen}, last " + "time was #{@total_req_rate[app_name]}" ) Djinn . log_debug ( "Requests currently in the queue #{total_req_in_queue}" ) requests_since_last_sampling = total_requests_seen - @total_req_rate [ app_name ] time_since_last_sampling = time_requests_were_seen - @last_sampling_time [ app_name ] if time_since_last_sampling . zero? time_since_last_sampling = 1 end average_request_rate = Float ( requests_since_last_sampling ) / Float ( time_since_last_sampling ) if average_request_rate < 0 Djinn . log_info ( "Saw negative request rate for app #{app_name}, so " + "resetting our haproxy stats for this app." ) initialize_scaling_info_for_app ( app_name , true ) return end if update_dashboard send_request_info_to_dashboard ( app_name , time_requests_were_seen , average_request_rate ) end Djinn . log_debug ( "Total requests will be set to #{total_requests_seen} " + "for app #{app_name}, with last sampling time #{time_requests_were_seen}" ) @current_req_rate [ app_name ] = total_req_in_queue @total_req_rate [ app_name ] = total_requests_seen @last_sampling_time [ app_name ] = time_requests_were_seen end
Updates internal state about the number of requests seen for the given App
Engine app, as well as how many requests are currently enqueued for it.
Updates internal state about the number of requests seen for the given App Engine app as well as how many requests are currently enqueued for it .
app_name
<not_specific>
total_requests_seen
<not_specific>
time_requests_were_seen
<not_specific>
total_req_in_queue
<not_specific>
update_dashboard
<not_specific>