All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.bdi.benchmarks.ReaderBenchmark Maven / Gradle / Ivy

Go to download

The Jadex BDI applications package contain several example applications, benchmarks and testcases using BDI agents.

There is a newer version: 2.4
Show newest version
package jadex.bdi.benchmarks;

import jadex.bdi.OAVBDIXMLReader;
import jadex.bdi.model.OAVBDIMetaModel;
import jadex.xml.reader.Reader;
import jadex.rules.state.IOAVState;
import jadex.rules.state.javaimpl.OAVStateFactory;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 *  Benchmark for OAV state memory consumption.
 *  Loads a model using jibx and OAV and compares the memory usage.
 */
public class ReaderBenchmark
{
	/**
	 *  Main for testing.
	 *  @throws IOException 
	 */
	public static void	main(String[] args) throws Exception
	{
		if(args.length!=1)
		{
			System.out.println("USAGE: ReaderBenchmark ");
			return;
		}

	//	Configuration.setFallbackConfiguration("jadex/config/batch_conf.properties");
		
		// Do not measure first loading.
		Reader	reader	= OAVBDIXMLReader.getReader(); 
		IOAVState	state	= OAVStateFactory.createOAVState(OAVBDIMetaModel.bdimm_type_model);
//		IOAVState	state	= new JenaOAVState();
		
//		Properties kernelprops = new Properties("", "", "");
//		kernelprops.addProperty(new Property("", "messagetype", "new jadex.base.fipa.FIPAMessageType()"));
		Map kernelprops = new HashMap();
		kernelprops.put("messagetype_fipa", new jadex.base.fipa.FIPAMessageType());
		
		Object	obj	= reader.read(new FileInputStream(args[0]), null, state);
		
		// Start tests.
		int cnt	= 100;
		gc();
		long	startmem	= Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();

		// Load OAV models.
		long	starttime	= System.currentTimeMillis();
		IOAVState[]	states	= loadOAVModels(args[0], reader, cnt);
		long	statetime	= System.currentTimeMillis() - starttime;
		gc();
		long	statemem	= Runtime.getRuntime().totalMemory() - startmem - Runtime.getRuntime().freeMemory();

		System.out.println("Start memory: "+calcKB(startmem)+" kb");
		System.out.println("State memory: "+calcKB(statemem)+" kb correponds to "+calcKB(statemem/(double)states.length)+" kb per agent.");
		System.out.println("State time: "+statetime+" millis correponds to "+statetime/states.length+" millis per agent.");
		
		// Keep VM alive for profiling.
		while(true)
		{
			synchronized(obj)
			{
				try
				{
					obj.wait();
				}
				catch(InterruptedException e){}
			}
		}
	}


	protected static IOAVState[] loadOAVModels(String arg, Reader reader, int cnt) throws Exception
	{
		IOAVState[] states	= new IOAVState[cnt];
		for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy