简体   繁体   中英

JADE agents using up heap space too quickly

The issue I am faced with is that when running a set of jade agents solving a simple problem the jvm runs out of heap space within 90s of operation depending on the amount of agents running. The goal of the agents is to balance load and generation in a simplified microgrid model, where several agents represent load and and another generation.

The load agents update the generator with a new value on each iteration of it's behaviour as shown in the following code:

    public class House9 extends Agent
    {
      double load  = 50;
      boolean offline = false;
      boolean valid = true;
      int counter = 0;
      double cur = 50;
      int next;

      public void setup()
      {

          addBehaviour(new SimpleBehaviour(this)
          {
             public void action()
             {
                //Adjusting load value
                if(counter == 0)
                {
                  load = (int)load;
                  cur = load;
                  next = 20+(int)(Math.random()*80);
                  //System.out.println("current: " + cur + " next " + next);
                  counter++;
                }
                else if(counter <= 1000)
                {
                  load = load + ((next - cur)/1000);
                  //System.out.println("added " + ((next - cur)/1000) +" to load");
                  counter++;
                }               
                else
                {
                  counter = 0;
                }

                //System.out.println("counter " + counter);

                //Sending result to the generator agent
                ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
                msg.setContent(Double.toString(load));
                msg.addReceiver(new AID("gen", AID.ISLOCALNAME));
                myAgent.send(msg);

           }
           public boolean done()
           {
              return offline;
           }
      });
}

All load agents are identical to this, and the generation agent is as follows:

    public class Generator extends Agent
    {
       int output = 100; 
       long time = System.currentTimeMillis();
       int iter = 0;


       public void setup()
       {
           System.out.println("Iterations,Time");

           addBehaviour(new CyclicBehaviour(this)
           {

               public void action()
               {
                   //myAgent.setQueueSize(2);
                     int temp = output;
                     ACLMessage reply = receive();

                     if(reply != null)
                     {
                        int load = Integer.parseInt(reply.getContent());
                        //System.out.println("current state--- output: " + output + " load: " + load);
                        if(load > output)
                        {
                           iter = 0;
                           while(load > output)
                           {
                               output = output + 10;
                               iter++;
                           }
                           //System.out.println((System.currentTimeMillis()-time)+ "," + iter );
                        }
                        else if(load < output)
                        {
                            iter = 0;
                            while(load < output)
                            {
                                output = output - 10;
                                iter--;
                            }
                            //System.out.println((System.currentTimeMillis()-time)+ "," + iter );

                        }

                        System.out.println((System.currentTimeMillis()-time)+ "," + iter + "," + load + "," + temp + "," + myAgent.getCurQueueSize());

                  }
              }
         });
      }
 }

From other posts on the internet about this sort of thing I have tried limiting the message queue size for the generation agent in case that was consuming the heap space, along with clearing through the jade message queue on the end of each generator behaviour iteration. But none of those seemed to make any difference, I tried adding more heap space but that only delayed the out of memory exception by a minute or so. The jade engine is called and the jade gui initiated through netbeans.

I am new at multi-agent programming and using jade, so I can appreciate there may be better and more more optimal ways of running this sort of system and that in itself might explain the problem. But would appreciate some help in the matter.

Thanks, Calum

The behaviour inside the House9 agent does not have any terminating condition. Each Agent will send a message each time the behaviour is scheduled. Since you have overridden the done method, they will continue to cycle through that behaviour sending messages out.

Do you mean to send so many messages? Should there be some sort of pause between messages? Your Generator Agent will try to process all these messages but it won't be able to keep up with the load in the Queue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM