Is the same visibility_timeout value being used to set TTL in unacked_mutex? - celery

To ensure our task gets executed by some worker regardless of the one that prefetched it being alive/stuck/killed we set the visibility_timeout parameter:
app.conf.broker_transport_options = {'visibility_timeout': 3600}
Is the same visibility_timeout value being used for specifying TTL (time-to-live) in unacked_mutex when it gets created, or there is another setting for this?

Related

Priority queue is not working in AnyLogic

I have two variables in agent
handicap = RandonTrue(0.3)
priority.
The priority variable value set in source exit based on wither agent is handicap or not, as shown in the image below.
Now in the queue I set Queuing to priority base and set agent priority to agent.priority . Shown in image below.
Note: Queue capacity is set to 10.
Now when I run the model and 10 agents enter I the queue, according to the priority handicap agents should be on the top of the queue but that is not happening. shown in the image below.
When the agents enter the delay after the queue, I also print their priorities on the console. The result is still the same, no priority is followed.
In the above image it is clear that they are not sorted based on priority.
Why priority queue is not working?
Moreover, I also changed the Queuing to LIFO, queue showed the same result, showing zero effect on agents.
this happens because contrary to the intuitive idea that events happen in the order you see, they don't... Things occur in the following order:
agent is created with the default value for the priority value
on at exit action is executed
the queue priority value is checked for the queue
the on exit action is executed
So from the point of view of the queue, the priority for all agents is the same
Solution
Instead of setting the priority value "on exit" do it on the "on at exit" action of the source block

Change priority rule of a Queue block at runtime in Anylogic

I am trying to implement reinforcement learning in Anylogic using pathmind library, the RL agent can take either of two actions which is changing the priority rule of a Queue block.
I have a Queue block where I'm using priority-based queueing. I have two priority rules: using agent's departure date & agent's wait time. I want to either of these rules during runtime using another function called doAction(action). A value 0 or 1 will be passed to this function. The function body would be like this:
doAction(action){
if(action==0){
//set departure_date as priority rule of Queueblock}
else{
//set wait_time as priority rule of Queueblock}
}
The expression of my queue block is given here. .
RL parameters are mentioned here.
What should be the code to set priority rule dynamically from the doAction(action) function?
I would suggest to rather make the priority rule dynamic inside the queue.
I assume you have some agent with a field for departureTime as well as for waitingTime.
Then you can do something like the following:
You simply have a different priority level for each agent if the priority option changes.
Here I am using boolean useDaprtureTime, but you can make it as complex as you need and even have a function in the "Agent Priority" field that returns the priority level.
Just remember that you need to call queue.sortAgents() if you change the rule since only the new agents that arrive are sorted, not the entire list of agents waiting in the queue since this will be too resource-intensive.
To use priorities, you specify an expression to determine the priority of the agent in the Queue's "Agent priority" or "Agent 1 is preferred to agent 2" property (depending what priority scheme you're using).
So have that expression be calling a function (defined within the agent type in question) which returns either the departure date or wait-time alternative.
Also, you didn't say whether this is a global setting --- i.e., use either departure or wait-time-based priorities for the whole run --- or could change dynamically; if you want the latter, you potentially need to call the sortAgents function of the Queue block (which might be inside a Service or Seize block, depending what you're doing) at the appropriate times (i.e., when your prioritisation scheme changes) to re-calculate all the priorities for agents currently waiting in the queue.
EDIT: I see from your other comment that you're trying to use reinforcement learning, presumably learning how to make a decision on how to prioritise the agents. (You should put that in an edit to your question since it's pretty important and relevant!)
So if you view the queue as the 'learning agent', you need to separate the learning action (which will set up / decide which prioritisation scheme you're using) from then using that scheme in the prioritisation.
This depends on whether you're using a Queue on its own (with priority based or agent comparison queueing), or you're doing this within a Service or Seize block. It matters because the on-enter action of the latter runs before the priority calculation expression but, with a plain Queue, it runs after the priority calculation.
Case 1: Using Service or Seize block
Have the on-enter action be the RL action which would then, say, set some variable to say which prioritisation scheme it had chosen and then call sortAgents on its embedded queue (self.queue) to recalc all the priorities. Then have switches in the priority calculation expression as above to do the calculation for the incoming agent using the required scheme.
Case 2: Using a plain Queue block
As above, but do the prioritisation scheme decision in the on-at-exit actions of all immediately preceding blocks (i.e., so that this is run just before the agent arrives at the Queue block and has its prioritisation allocated).
You can always use 2 queue blocks and send agents to only one using a SelectOutput block in front of them.
Each agent decides which queue to use based on your conditions.

how to Vary process times for agents , and call it during Delay block

There is a process/delay block which should process agents with different timings, how do I perform this?
Initially I thought I could assign a parameter and change this for each agent, and the delay block would process agents according to time specified in Parameter.
If the delay depends on each agent, you need to create an agent type in which you add a parameter, let's say you call it delayTime. Then, you can access this parameter in the flow charts by calling
agent.delayTime;
You can write the above in the delay time field of the delay block.
Check:
https://help.anylogic.com/topic/com.anylogic.help/html/processmodeling/agent-type.html?resultof=%22%63%75%73%74%6f%6d%22%20%22%61%67%65%6e%74%22%20%22%74%79%70%65%22%20

How to set wait timeout for a queue in Amazon redshift?

I know there exists a wlm timeout which times out when the query 'executes' more than that time. But can i set a timeout for the amount of time a query waits in the queue ?
You can control the amount of time that query spends waiting in queue indirectly by specifying statement_timeout configuration parameter on session or whole cluster level in addition to max_execution_time parameter on WLM level. If both WLM timeout (max_execution_time) and statement_timeout are specified, the shorter timeout is used. In this case the maximum time that query will be able to wait in the queue is "statement_timeout" minus "max_execution_time".
You can modify your WLM configuration to create separate queues for the queries on the basis of time they require to run and at runtime, you can route queries to the queues according to user groups or query groups. Hope that is what you want.

How can I set priorities to quartz trigger?

I am using Quartz Scheduler and there are 15 jobs. For each job there is one trigger.
I want to set priority for each trigger. I can set low priority as 10 and high priority as 1.
But as I am having 15 triggers for 15 jobs I need different priority for each trigger.
e.g trigger1 will have priority 10, trigger2 will have priority 9.
In this way I need to give same priority for two triggers.
So if two triggers with same priority will get execute at same time then which trigger will execute first?
Can anyone tell me how I can set different priorities for different triggers?
Trigger have a property called WithPriority which takes a integer value. When multiple triggers are fired at the same time the scheduler will fire the trigger with the highest priority first. And if the two triggers have same priority then either trigger will get fired.
.WithPriority(15) will run first
.WithPriority(1) will be the last trigger
Triggers have a 'priority' property on them. Just set the property accordingly as the triggers are created, or use the api to retrieve the triggers, set the priorities, and reschedule them.
If two or more triggers have the same fire time and same priority, one will be randomly chosen for firing first (what else could the ordering be based on?).