Optimization of test goal execution

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Optimization of test goal execution

Nikolay Ryabykh
Hi, everyone!

I encountered the following problem while using Jason. 
In my project agent's belief base is rather big. It contains about 100,000 beliefs. The agent needs to search through these beliefs and send them to other agents (according to some rules). The problem is that the searching through this base (i.e. test goal execution) takes unacceptable time. 

I wrote a simple example:

!start.
+!start <- 
.print("Start");
for ( .range(I, 1, 100000)) {
Value = math.random(10);
+belief(counter(I), value(Value));
}
for ( .range(J, 1, 100000)) {
?belief(counter(J), value(Value));
.print("Counter = ", J, ", Value = ", Value);
}
.print("End");
.

In this example printing all beliefs takes a lot of time. But after removing test goal ?belief, it takes few second to finish.

Could you please give me a hint about how to optimize search through belief base?

--
Best regards,
Nikolay Ryabykh.

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
Jason-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jason-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Optimization of test goal execution

Rafael H Bordini-2
Hi Nikolay,

The belief base works more or less like a logic program. This means it normally checks if your query is a logical consequence of the belief base. There is already an optimisation in the way Jason retrieves relevant beliefs and rules from the belief base, which has to do with the predicate name and arity (it's used as index to a hash table). You are not able to take advantage of that because all your beliefs have the same predicate name and arity ("belief/2"), hence Jason needs to try to match the query with every single belief it has, in the worst case. If this was just to test and your actual belief base will be different, maybe you won't have so big a problem. If this is what you need in your belief base, than a logical belief base isn't what you need after all. You'd be better off customising your belief base by reprogramming it in Java so that when a counter/value pair is retrieved, you get it from a Java data structure, or if it's more complicated than that use the already available belief base customisation to access a database. There are some examples of belief base customisation in the distribution and also in the Jason book.

HTH,

Rafael


On 30/01/2013 13:59, Nikolay Ryabykh wrote:
Hi, everyone!

I encountered the following problem while using Jason. 
In my project agent's belief base is rather big. It contains about 100,000 beliefs. The agent needs to search through these beliefs and send them to other agents (according to some rules). The problem is that the searching through this base (i.e. test goal execution) takes unacceptable time. 

I wrote a simple example:

!start.
+!start <- 
.print("Start");
for ( .range(I, 1, 100000)) {
Value = math.random(10);
+belief(counter(I), value(Value));
}
for ( .range(J, 1, 100000)) {
?belief(counter(J), value(Value));
.print("Counter = ", J, ", Value = ", Value);
}
.print("End");
.

In this example printing all beliefs takes a lot of time. But after removing test goal ?belief, it takes few second to finish.

Could you please give me a hint about how to optimize search through belief base?

--
Best regards,
Nikolay Ryabykh.


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan


_______________________________________________
Jason-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jason-users


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
Jason-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jason-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Optimization of test goal execution

Jomi Hubner
In reply to this post by Nikolay Ryabykh
Dear Nikolay,

thanks for sharing this issue!

First, the reason for the bad performance. Beliefs are stored in a hash table with the belief functor + arity as the key. So, all your beliefs goes to the same entry in the hash table, forming a single list.

Second, possible solutions.
a) use different functors/arity for your beliefs. Of course, for some application it is not possible/reasonable.

b) customize the belief base to consider the first term of the predicate as primary key. There is an initial prototype for this kind of Belief base in src/jason/bb/IndexedBB.java. However this class only deals with unique primary keys and still do not optimize the consult of its values.

c) use a relational data base for your belief base (e.g. MySQL) and define the first term as primary key.

HTH,

Jomi


On 30/01/2013, at 13:59, Nikolay Ryabykh wrote:

> Hi, everyone!
>
> I encountered the following problem while using Jason.
> In my project agent's belief base is rather big. It contains about 100,000 beliefs. The agent needs to search through these beliefs and send them to other agents (according to some rules). The problem is that the searching through this base (i.e. test goal execution) takes unacceptable time.
>
> I wrote a simple example:
>
> !start.
> +!start <-
> .print("Start");
> for ( .range(I, 1, 100000)) {
> Value = math.random(10);
> +belief(counter(I), value(Value));
> }
> for ( .range(J, 1, 100000)) {
> ?belief(counter(J), value(Value));
> .print("Counter = ", J, ", Value = ", Value);
> }
> .print("End");
> .
>
> In this example printing all beliefs takes a lot of time. But after removing test goal ?belief, it takes few second to finish.
>
> Could you please give me a hint about how to optimize search through belief base?
>
> --
> Best regards,
> Nikolay Ryabykh.
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_jan_______________________________________________
> Jason-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jason-users

--
Jomi Fred Hubner
Federal University of Santa Catarina
Department of Automation and Systems Engineering
PO Box 476, Florianópolis, SC
88040-900 Brazil
http://www.das.ufsc.br/~jomi


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
Jason-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jason-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Optimization of test goal execution

Nikolay Ryabykh
Rafael, Jomi,

We tried to use IndexedBB, but performance gain was insignificant. But we managed to split our huge BB into several parts with different functors - and it works great! It helps us to improve performance by seven times!

Thanks a lot for your assistance! 


2013/2/4 Jomi Hubner <[hidden email]>
Dear Nikolay,

thanks for sharing this issue!

First, the reason for the bad performance. Beliefs are stored in a hash table with the belief functor + arity as the key. So, all your beliefs goes to the same entry in the hash table, forming a single list.

Second, possible solutions.
a) use different functors/arity for your beliefs. Of course, for some application it is not possible/reasonable.

b) customize the belief base to consider the first term of the predicate as primary key. There is an initial prototype for this kind of Belief base in src/jason/bb/IndexedBB.java. However this class only deals with unique primary keys and still do not optimize the consult of its values.

c) use a relational data base for your belief base (e.g. MySQL) and define the first term as primary key.

HTH,

Jomi


On 30/01/2013, at 13:59, Nikolay Ryabykh wrote:

> Hi, everyone!
>
> I encountered the following problem while using Jason.
> In my project agent's belief base is rather big. It contains about 100,000 beliefs. The agent needs to search through these beliefs and send them to other agents (according to some rules). The problem is that the searching through this base (i.e. test goal execution) takes unacceptable time.
>
> I wrote a simple example:
>
> !start.
> +!start <-
>       .print("Start");
>       for ( .range(I, 1, 100000)) {
>               Value = math.random(10);
>               +belief(counter(I), value(Value));
>       }
>       for ( .range(J, 1, 100000)) {
>               ?belief(counter(J), value(Value));
>               .print("Counter = ", J, ", Value = ", Value);
>       }
>       .print("End");
> .
>
> In this example printing all beliefs takes a lot of time. But after removing test goal ?belief, it takes few second to finish.
>
> Could you please give me a hint about how to optimize search through belief base?
>
> --
> Best regards,
> Nikolay Ryabykh.
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_jan_______________________________________________
> Jason-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jason-users

--
Jomi Fred Hubner
Federal University of Santa Catarina
Department of Automation and Systems Engineering
PO Box 476, Florianópolis, SC
88040-900 Brazil
http://www.das.ufsc.br/~jomi




--
С уважением,
Николай Рябых.

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Jason-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jason-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Optimization of test goal execution

Jomi Hubner
Hi,

that is really good news! 

Indeed the IndexedBB needs to be improved to use primary key to speed up the search time. Currently, it only avoid two beliefs with the same key.

all the best for your project.

jomi

On 05/02/2013, at 03:56, Nikolay Ryabykh wrote:

Rafael, Jomi,

We tried to use IndexedBB, but performance gain was insignificant. But we managed to split our huge BB into several parts with different functors - and it works great! It helps us to improve performance by seven times!

Thanks a lot for your assistance! 


2013/2/4 Jomi Hubner <[hidden email]>
Dear Nikolay,

thanks for sharing this issue!

First, the reason for the bad performance. Beliefs are stored in a hash table with the belief functor + arity as the key. So, all your beliefs goes to the same entry in the hash table, forming a single list.

Second, possible solutions.
a) use different functors/arity for your beliefs. Of course, for some application it is not possible/reasonable.

b) customize the belief base to consider the first term of the predicate as primary key. There is an initial prototype for this kind of Belief base in src/jason/bb/IndexedBB.java. However this class only deals with unique primary keys and still do not optimize the consult of its values.

c) use a relational data base for your belief base (e.g. MySQL) and define the first term as primary key.

HTH,

Jomi


On 30/01/2013, at 13:59, Nikolay Ryabykh wrote:

> Hi, everyone!
>
> I encountered the following problem while using Jason.
> In my project agent's belief base is rather big. It contains about 100,000 beliefs. The agent needs to search through these beliefs and send them to other agents (according to some rules). The problem is that the searching through this base (i.e. test goal execution) takes unacceptable time.
>
> I wrote a simple example:
>
> !start.
> +!start <-
>       .print("Start");
>       for ( .range(I, 1, 100000)) {
>               Value = math.random(10);
>               +belief(counter(I), value(Value));
>       }
>       for ( .range(J, 1, 100000)) {
>               ?belief(counter(J), value(Value));
>               .print("Counter = ", J, ", Value = ", Value);
>       }
>       .print("End");
> .
>
> In this example printing all beliefs takes a lot of time. But after removing test goal ?belief, it takes few second to finish.
>
> Could you please give me a hint about how to optimize search through belief base?
>
> --
> Best regards,
> Nikolay Ryabykh.
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_jan_______________________________________________
> Jason-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jason-users

--
Jomi Fred Hubner
Federal University of Santa Catarina
Department of Automation and Systems Engineering
PO Box 476, Florianópolis, SC
88040-900 Brazil
http://www.das.ufsc.br/~jomi




--
С уважением,
Николай Рябых.

-- 
Jomi Fred Hubner
Federal University of Santa Catarina
Department of Automation and Systems Engineering
PO Box 476, Florianópolis, SC
88040-900 Brazil


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Jason-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jason-users
Loading...