AppController/djinn.rb
# An Array of DjinnJobData objects, each of which containing information about
# a node in the currently running AppScale deployment.
An Array of DjinnJobData objects, each of which containing information about
a node in the currently running AppScale deployment.
An Array of DjinnJobData objects each of which containing information about a node in the currently running AppScale deployment .
def try_to_scale_up(app_name)
    if @app_info_map[app_name].nil? || !@app_names.include?(app_name)
      Djinn.log_info("Not scaling up app #{app_name}, since we aren't " +
        "hosting it anymore.")
      return
    end
    if Time.now.to_i - @last_decision[app_name] < SCALEUP_THRESHOLD * DUTY_CYCLE
      Djinn.log_debug("Not enough time as passed to scale up app #{app_name}")
      return
    end
    appservers_running = get_all_appengine_nodes()
    available_hosts = {}
    appservers_running.each { |host|
      @all_stats.each { |node|
        if node['private_ip'] == host
          if Float(node['free_memory']) > Integer(@options['max_memory']) + SAFE_MEM and
              Float(node['cpu']) < MAX_CPU_FOR_APPSERVERS and
              Float(node['load']) / Float(node['num_cpu']) < MAX_LOAD_AVG
            available_hosts[host] = (Float(node['load']) / Float(node['num_cpu']))
          else
            Djinn.log_debug("#{host} is too busy: not using it to scale #{app_name}")
          end
          break         
        end
      }
    }
    if available_hosts.keys[0] != nil
      appserver_to_use = []
      appengine_running = []
      if @app_info_map[app_name]['appengine']
        @app_info_map[app_name]['appengine'].each { |location|
          host, port = location.split(":")
          appengine_running << host
        }
        Djinn.log_debug("These hosts are running #{app_name}: #{appengine_running}.")
        available_hosts.each { |host, load|
          unless appengine_running.include?(host)
            Djinn.log_debug("Prioritizing #{host} to run #{app_name} " +
                "since it has no running AppServers for it.")
            appserver_to_use = host
            break
          end
        }
      end
      if appserver_to_use.empty?
        appserver_to_use = available_hosts.keys[0]
        available_hosts.each { |host, load|
          appserver_to_use = host if available_hosts[appserver_to_use] > load
        }
      end
      Djinn.log_info("Adding a new AppServer on #{appserver_to_use} for #{app_name}")
      @app_info_map[app_name]['appengine'] << "#{appserver_to_use}:-1"
      @last_decision[app_name] = Time.now.to_i
    else
      Djinn.log_info("No AppServer available to scale #{app_name}")
      ZKInterface.request_scale_up_for_app(app_name, my_node.private_ip)
    end
  end
def try_to_scale_up ( app_name ) if @app_info_map [ app_name ] . nil? || ! @app_names . include? ( app_name ) Djinn . log_info ( "Not scaling up app #{app_name}, since we aren't " + "hosting it anymore." ) return end if Time . now . to_i - @last_decision [ app_name ] < SCALEUP_THRESHOLD * DUTY_CYCLE Djinn . log_debug ( "Not enough time as passed to scale up app #{app_name}" ) return end appservers_running = get_all_appengine_nodes ( ) available_hosts = { } appservers_running . each { | host | @all_stats . each { | node | if node [ 'private_ip' ] == host if Float ( node [ 'free_memory' ] ) > Integer ( @options [ 'max_memory' ] ) + SAFE_MEM and Float ( node [ 'cpu' ] ) < MAX_CPU_FOR_APPSERVERS and Float ( node [ 'load' ] ) / Float ( node [ 'num_cpu' ] ) < MAX_LOAD_AVG available_hosts [ host ] = ( Float ( node [ 'load' ] ) / Float ( node [ 'num_cpu' ] ) ) else Djinn . log_debug ( "#{host} is too busy: not using it to scale #{app_name}" ) end break end } } if available_hosts . keys [ 0 ] != nil appserver_to_use = [ ] appengine_running = [ ] if @app_info_map [ app_name ] [ 'appengine' ] @app_info_map [ app_name ] [ 'appengine' ] . each { | location | host , port = location . split ( ":" ) appengine_running << host } Djinn . log_debug ( "These hosts are running #{app_name}: #{appengine_running}." ) available_hosts . each { | host , load | unless appengine_running . include? ( host ) Djinn . log_debug ( "Prioritizing #{host} to run #{app_name} " + "since it has no running AppServers for it." ) appserver_to_use = host break end } end if appserver_to_use . empty? appserver_to_use = available_hosts . keys [ 0 ] available_hosts . each { | host , load | appserver_to_use = host if available_hosts [ appserver_to_use ] > load } end Djinn . log_info ( "Adding a new AppServer on #{appserver_to_use} for #{app_name}" ) @app_info_map [ app_name ] [ 'appengine' ] << "#{appserver_to_use}:-1" @last_decision [ app_name ] = Time . now . to_i else Djinn . log_info ( "No AppServer available to scale #{app_name}" ) ZKInterface . request_scale_up_for_app ( app_name , my_node . private_ip ) end end
An Array of DjinnJobData objects, each of which containing information about
a node in the currently running AppScale deployment.
An Array of DjinnJobData objects each of which containing information about a node in the currently running AppScale deployment .
# We scale only if the designed time is passed. # All the available appengine servers. # Select an appengine machine if it has enough resources to support # another AppServer for this app. # The host needs to have normalized average load less than # MAX_LOAD_AVG, current CPU usage less than 90% and enough # memory to run an AppServer (and some safe extra). # We found the host's statistics. # Now let's prefer hosts that are not already running a copy of this # app. Otherwise we select the host with the lowest load. # If we didn't find any unused host, we will pick the least loaded. # If we're this far, no room is available for AppServers, so try to add a # new node instead.
app_name
<not_specific>