cctools
bucketing_manager.h
1#ifndef BUCKETING_MANAGER_H
2#define BUCKETING_MANAGER_H
3
4#include "rmsummary.h"
5#include "hash_table.h"
6#include "bucketing_greedy.h"
7#include "bucketing_exhaust.h"
8
9/* A bucketing manager has its bucketing mode, a table mapping resource
10 * type to its bucketing state, and a table mapping task id to its latest
11 * resource summary */
12typedef struct
13{
14 bucketing_mode_t mode; //bucketing mode
15 struct hash_table* res_type_to_bucketing_state; //mapping of resource type to bucketing state
16 struct hash_table* task_id_to_task_rmsummary; //mapping of task id to its previous resource summary from either actual run or prediction
17}
19
20/* Create a bucketing manager
21 * @param mode bucketing mode of manager
22 * @return pointer to a newly created bucketing manager */
23bucketing_manager_t* bucketing_manager_create(bucketing_mode_t mode);
24
25/* Create and initialize a bucketing manager
26 * @param mode algorithm to do bucketing
27 * @return pointer to a created and initialized bucketing manager */
28bucketing_manager_t* bucketing_manager_initialize(bucketing_mode_t mode);
29
30/* Delete a bucketing manager
31 * @param m the manager to be deleted */
32void bucketing_manager_delete(bucketing_manager_t* m);
33
34/* Add a new type of resource to the manager
35 * Do nothing if this resource is already in manager
36 * @param m the relevant manager
37 * @param r the string of the resource (e.g., "cores")
38 * @param set_default set default values for resource, only support cores, memory, and disk and ignore the rest of the arguments
39 * see this function's definition for more info
40 * @param default_value the first base value to allocate new tasks (e.g.,"mem": 1000 means try 1GBs of mem to new tasks)
41 * @param num_sampling_points number of sampling points
42 * @param increase_rate the rate to increase value when task fails in sampling phase or when task consumes more than any other tasks in predicting phase
43 * @param max_num_buckets the maximum number of buckets to try to break (only for EXHAUSTIVE_BUCKETING)
44 * @param update_epoch the number of iterations before rebucketing */
45void bucketing_manager_add_resource_type(bucketing_manager_t* m, const char* r,
46 int set_default, double default_value, int num_sampling_points,
47 double increase_rate, int max_num_buckets, int update_epoch);
48
49/* Remove a type of resource from the manager
50 * Do nothing if this resource is not in manager
51 * @param m the relevant manager
52 * @param r the string of the resource (e.g., "cores") */
53void bucketing_manager_remove_resource_type(bucketing_manager_t* m, const char* r);
54
55/* Set the bucketing algorithm of a manager
56 * @param m the relevant manager
57 * @param mode the mode of algorithm to change to */
58void bucketing_manager_set_mode(bucketing_manager_t* m, bucketing_mode_t mode);
59
60/* Tune the bucketing state by resource
61 * @param m the bucketing manager
62 * @param res_name the name of resource to tune its bucketing state
63 * @param field the field in bucketing state to tune
64 * @param val the value of field */
65void bucketing_manager_tune_by_resource(bucketing_manager_t* m, const char* res_name,
66 const char* field, void* val);
67
68/* Given a task id, the manager returns a predicted allocation and adds this prediction into internal state. The caller is responsible for free'ing the returned value.
69 * @param m the relevant manager
70 * @param task_id the task id
71 * @return a pointer to a newly created rmsummary containing the prediction
72 * this rmsummary's entries are 0 if no prediction, otherwise entries are predicted
73 * @return 0 if failure */
74struct rmsummary* bucketing_manager_predict(bucketing_manager_t* m, int task_id);
75
76/* Add a task's resource summary to the manager. The caller is responsible for free'ing the parameter r after calling this function. This function should only be called when task succeeds or fails due to resource exhaustion
77 * @param m the relevant manager
78 * @param task_id task id of task to be added
79 * @param r the resource summary of a task
80 * @param success whether task succeeds in running or not (i.e., task doesn't exceed resource limits) (1 is yes 0 is no) */
81void bucketing_manager_add_resource_report(bucketing_manager_t* m, int task_id, struct rmsummary* r, int success);
82
83#endif
A general purpose hash table.
Definition bucketing_manager.h:13
Definition rmsummary.h:27