-
Notifications
You must be signed in to change notification settings - Fork 18
/
BatchComputeService.h
345 lines (251 loc) · 15.1 KB
/
BatchComputeService.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/**
* Copyright (c) 2017. The WRENCH Team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#ifndef WRENCH_BATCH_SERVICE_H
#define WRENCH_BATCH_SERVICE_H
#include "wrench/services/compute/ComputeService.h"
#include "wrench/services/compute/standard_job_executor/StandardJobExecutor.h"
#include "wrench/services/compute/batch/BatchJob.h"
#include "wrench/services/compute/batch/BatschedNetworkListener.h"
#include "wrench/services/compute/batch/BatchComputeServiceProperty.h"
#include "wrench/services/compute/batch/BatchComputeServiceMessagePayload.h"
#include "wrench/services/helpers/Alarm.h"
#include "wrench/workflow/job/StandardJob.h"
#include "wrench/workflow/job/WorkflowJob.h"
#include <deque>
#include <queue>
#include <set>
#include <tuple>
namespace wrench {
class WorkloadTraceFileReplayer; // forward
/**
* @brief A batch-scheduled compute service that manages a set of compute hosts and
* controls access to their resource via a batch queue.
*
* In the current implementation of
* this service, like for many of its real-world counterparts, memory
* partitioning among jobs on the same host is not handled. When multiple jobs share hosts,
* which can happen when jobs require only a few cores per host and can thus
* be co-located on the same hosts in a non-exclusive fashion,
* each job simply runs as if it had access to the
* full RAM of each compute host it is scheduled on. The simulation of these
* memory contended scenarios is thus, for now, not realistic as there is no simulation
* of the effects
* of memory sharing (e.g., swapping).
*/
class BatchComputeService : public ComputeService {
/**
* @brief A Batch Service
*/
private:
std::map<std::string, std::string> default_property_values = {
{BatchComputeServiceProperty::SUPPORTS_PILOT_JOBS, "true"},
{BatchComputeServiceProperty::SUPPORTS_STANDARD_JOBS, "true"},
{BatchComputeServiceProperty::TASK_STARTUP_OVERHEAD, "0"},
{BatchComputeServiceProperty::HOST_SELECTION_ALGORITHM, "FIRSTFIT"},
{BatchComputeServiceProperty::TASK_SELECTION_ALGORITHM, "maximum_flops"},
#ifdef ENABLE_BATSCHED
{BatchComputeServiceProperty::BATCH_SCHEDULING_ALGORITHM, "conservative_bf"},
// {BatchComputeServiceProperty::BATCH_SCHEDULING_ALGORITHM, "easy_bf"},
// {BatchComputeServiceProperty::BATCH_SCHEDULING_ALGORITHM, "easy_bf_fast"},
{BatchComputeServiceProperty::BATCH_QUEUE_ORDERING_ALGORITHM, "fcfs"},
#else
{BatchComputeServiceProperty::BATCH_SCHEDULING_ALGORITHM, "FCFS"},
#endif
{BatchComputeServiceProperty::BATCH_RJMS_DELAY, "0"},
{BatchComputeServiceProperty::SIMULATED_WORKLOAD_TRACE_FILE, ""},
{BatchComputeServiceProperty::USE_REAL_RUNTIMES_AS_REQUESTED_RUNTIMES_IN_WORKLOAD_TRACE_FILE, "false"},
{BatchComputeServiceProperty::IGNORE_INVALID_JOBS_IN_WORKLOAD_TRACE_FILE, "false"},
{BatchComputeServiceProperty::SUBMIT_TIME_OF_FIRST_JOB_IN_WORKLOAD_TRACE_FILE, "-1"},
{BatchComputeServiceProperty::OUTPUT_CSV_JOB_LOG, ""},
{BatchComputeServiceProperty::SIMULATE_COMPUTATION_AS_SLEEP, "false"},
{BatchComputeServiceProperty::BATSCHED_LOGGING_MUTED, "true"},
{BatchComputeServiceProperty::BATSCHED_CONTIGUOUS_ALLOCATION, "false"}
};
std::map<std::string, double> default_messagepayload_values = {
{BatchComputeServiceMessagePayload::STOP_DAEMON_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::RESOURCE_DESCRIPTION_REQUEST_MESSAGE_PAYLOAD,1024},
{BatchComputeServiceMessagePayload::RESOURCE_DESCRIPTION_ANSWER_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::DAEMON_STOPPED_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::STANDARD_JOB_DONE_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::SUBMIT_STANDARD_JOB_REQUEST_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::SUBMIT_STANDARD_JOB_ANSWER_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::TERMINATE_STANDARD_JOB_REQUEST_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::TERMINATE_STANDARD_JOB_ANSWER_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::SUBMIT_PILOT_JOB_REQUEST_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::SUBMIT_PILOT_JOB_ANSWER_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::STANDARD_JOB_FAILED_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::PILOT_JOB_STARTED_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::PILOT_JOB_EXPIRED_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::TERMINATE_PILOT_JOB_ANSWER_MESSAGE_PAYLOAD, 1024},
{BatchComputeServiceMessagePayload::TERMINATE_PILOT_JOB_REQUEST_MESSAGE_PAYLOAD, 1024},
};
public:
BatchComputeService(std::string &hostname,
std::vector<std::string> compute_hosts,
std::string scratch_space_mount_point,
std::map<std::string, std::string> property_list = {},
std::map<std::string, double> messagepayload_list = {}
);
/***********************/
/** \cond DEVELOPER **/
/***********************/
std::map<std::string,double> getStartTimeEstimates(std::set<std::tuple<std::string,unsigned int,unsigned int, double>> resources);
/***********************/
/** \endcond **/
/***********************/
/***********************/
/** \cond INTERNAL **/
/***********************/
~BatchComputeService() override;
/***********************/
/** \endcond **/
/***********************/
private:
friend class WorkloadTraceFileReplayer;
BatchComputeService(std::string hostname,
std::vector<std::string> compute_hosts,
unsigned long cores_per_host,
double ram_per_host,
std::string scratch_space_mount_point,
std::map<std::string, std::string> property_list,
std::map<std::string, double> messagepayload_list,
std::string suffix
);
// helper function
static unsigned long parseUnsignedLongServiceSpecificArgument(std::string key, std::map<std::string, std::string> &args);
// helper function
void submitWorkflowJob(WorkflowJob *job, std::map<std::string, std::string> &batch_job_args);
//submits a standard job
void submitStandardJob(StandardJob *job, std::map<std::string, std::string> &batch_job_args) override;
//submits a standard job
void submitPilotJob(PilotJob *job, std::map<std::string, std::string> &batch_job_args) override;
// helper function
void terminateWorkflowJob(WorkflowJob *job);
// terminate a standard job
void terminateStandardJob(StandardJob *job) override;
// terminate a pilot job
void terminatePilotJob(PilotJob *job) override;
std::vector<std::tuple<std::string, double, double, double, double, unsigned int>> workload_trace;
std::shared_ptr<WorkloadTraceFileReplayer> workload_trace_replayer;
bool clean_exit = false;
//Configuration to create randomness in measurement period initially
unsigned long random_interval = 10;
//create alarms for standard jobs
std::map<std::string,std::shared_ptr<Alarm>> standard_job_alarms;
//alarms for pilot jobs (only one pilot job alarm)
std::map<std::string,std::shared_ptr<Alarm>> pilot_job_alarms;
/* Resources information in Batchservice */
unsigned long total_num_of_nodes;
unsigned long num_cores_per_node;
std::map<std::string, unsigned long> nodes_to_cores_map;
std::vector<double> timeslots;
std::map<std::string, unsigned long> available_nodes_to_cores;
std::map<unsigned long, std::string> host_id_to_names;
std::vector<std::string> compute_hosts;
/*End Resources information in Batchservice */
// Vector of standard job executors
std::set<std::shared_ptr<StandardJobExecutor>> running_standard_job_executors;
// Vector of standard job executors (which is cleared periodically)
std::set<std::shared_ptr<StandardJobExecutor>> finished_standard_job_executors;
// Master List of batch jobs
std::set<std::unique_ptr<BatchJob>> all_jobs;
//Queue of pending batch jobs
std::deque<BatchJob *> pending_jobs;
//A set of running batch jobs
std::set<BatchJob *> running_jobs;
// A set of waiting jobs that have been submitted to batsched, but not scheduled
std::set<BatchJob *> waiting_jobs;
#ifdef ENABLE_BATSCHED
std::set<std::string> scheduling_algorithms = {"conservative_bf", "crasher", "easy_bf", "easy_bf_fast",
"easy_bf_plot_liquid_load_horizon",
"energy_bf", "energy_bf_dicho", "energy_bf_idle_sleeper",
"energy_bf_monitoring",
"energy_bf_monitoring_inertial", "energy_bf_subpart_sleeper",
"energy_watcher", "fcfs_fast", "fast_conservative_bf",
"filler", "killer", "killer2", "random", "rejecter",
"sequencer", "sleeper", "submitter", "waiting_time_estimator"
};
std::set<std::string> queue_ordering_options = {"fcfs", "lcfs", "desc_bounded_slowdown", "desc_slowdown",
"asc_size", "desc_size", "asc_walltime", "desc_walltime"
};
#else
std::set<std::string> scheduling_algorithms = {"FCFS"
};
//Batch queue ordering options
std::set<std::string> queue_ordering_options = {
};
#endif
unsigned long generateUniqueJobID();
void removeJobFromRunningList(BatchJob *job);
void freeJobFromJobsList(BatchJob* job);
int main() override;
bool processNextMessage();
void startBackgroundWorkloadProcess();
void processGetResourceInformation(const std::string &answer_mailbox);
void processStandardJobCompletion(std::shared_ptr<StandardJobExecutor> executor, StandardJob *job);
void processStandardJobFailure(std::shared_ptr<StandardJobExecutor> executor,
StandardJob *job,
std::shared_ptr<FailureCause> cause);
void terminateRunningStandardJob(StandardJob *job);
std::map<std::string, std::tuple<unsigned long, double>> scheduleOnHosts(std::string host_selection_algorithm,
unsigned long, unsigned long, double);
BatchJob *pickJobForScheduling(std::string);
//Terminate the batch service (this is usually for pilot jobs when they act as a batch service)
void cleanup(bool has_returned_from_main, int return_value) override;
// Terminate currently running pilot jobs
void terminateRunningPilotJobs();
//Fail the standard jobs
void failCurrentStandardJobs();
//Process the pilot job completion
void processPilotJobCompletion(PilotJob *job);
//Process standardjob timeout
void processStandardJobTimeout(StandardJob *job);
//process standard job termination request
void processStandardJobTerminationRequest(StandardJob *job, std::string answer_mailbox);
//process pilot job termination request
void processPilotJobTerminationRequest(PilotJob *job, std::string answer_mailbox);
// process a batch job tiemout event
void processAlarmJobTimeout(BatchJob *job);
//Process pilot job timeout
void processPilotJobTimeout(PilotJob *job);
//free up resources
void freeUpResources(std::map<std::string, std::tuple<unsigned long, double>> resources);
//send call back to the pilot job submitters
void sendPilotJobExpirationNotification(PilotJob *job);
//send call back to the standard job submitters
void sendStandardJobFailureNotification(StandardJob *job, std::string job_id, std::shared_ptr<FailureCause> cause);
// Try to schedule a job
bool scheduleOneQueuedJob();
// process a job submission
void processJobSubmission(BatchJob *job, std::string answer_mailbox);
//start a job
void startJob(std::map<std::string, std::tuple<unsigned long, double>>, WorkflowJob *,
BatchJob *, unsigned long, unsigned long, unsigned long);
//vector of network listeners (only useful when ENABLE_BATSCHED == on)
std::map<std::string,double> getStartTimeEstimatesForFCFS(std::set<std::tuple<std::string,unsigned int,unsigned int, double>>);
/** BATSCHED-related fields **/
std::set<std::shared_ptr<BatschedNetworkListener>> network_listeners;
pid_t pid;
unsigned long batsched_port;
#ifdef ENABLE_BATSCHED
friend class BatschedNetworkListener;
void startBatsched();
void stopBatsched();
std::map<std::string,double> getStartTimeEstimatesFromBatsched(std::set<std::tuple<std::string,unsigned int,unsigned int,double>>);
void startBatschedNetworkListener();
void notifyJobEventsToBatSched(std::string job_id, std::string status, std::string job_state,
std::string kill_reason, std::string even_type);
void appendJobInfoToCSVOutputFile(BatchJob *batch_job, std::string status);
void sendAllQueuedJobsToBatsched();
//process execute events from batsched
void processExecuteJobFromBatSched(std::string bat_sched_reply);
#endif // ENABLE_BATSCHED
};
}
#endif //WRENCH_BATCH_SERVICE_H