Skip to content

Commit 971b4e5

Browse files
committed
resource: use drainset in drain_get_info()
Problem: Generating the resource.status drain response in-place as is currently done in drain_get_info() is very slow when there are many drained ranks. Use the drainset class to generate the object returned by drain_get_info(). This should be much faster since the JSON object is generated once after all like ranks have been collected together. Fixes #5856
1 parent 11df56e commit 971b4e5

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

src/modules/resource/drain.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "drain.h"
5353
#include "rutil.h"
5454
#include "inventory.h"
55+
#include "drainset.h"
5556

5657
struct draininfo {
5758
bool drained;
@@ -272,34 +273,23 @@ static void broker_torpid_cb (flux_future_t *f, void *arg)
272273

273274
json_t *drain_get_info (struct drain *drain)
274275
{
275-
json_t *o;
276-
unsigned int rank;
277-
278-
if (!(o = json_object ()))
279-
goto nomem;
280-
for (rank = 0; rank < drain->ctx->size; rank++) {
276+
json_t *o = NULL;
277+
struct drainset *ds = drainset_create ();
278+
if (!ds)
279+
goto error;
280+
for (unsigned int rank = 0; rank < drain->ctx->size; rank++) {
281281
if (drain->info[rank].drained) {
282-
char *reason = drain->info[rank].reason;
283-
json_t *val;
284-
if (!(val = json_pack ("{s:f s:s}",
285-
"timestamp",
286-
drain->info[rank].timestamp,
287-
"reason",
288-
reason ? reason : "")))
289-
goto nomem;
290-
if (rutil_idkey_insert_id (o, rank, val) < 0) {
291-
ERRNO_SAFE_WRAP (json_decref, val);
282+
if (drainset_drain_rank (ds,
283+
rank,
284+
drain->info[rank].timestamp,
285+
drain->info[rank].reason) < 0)
292286
goto error;
293-
}
294-
json_decref (val);
295287
}
296288
}
297-
return o;
298-
nomem:
299-
errno = ENOMEM;
289+
o = drainset_to_json (ds);
300290
error:
301-
ERRNO_SAFE_WRAP (json_decref, o);
302-
return NULL;
291+
drainset_destroy (ds);
292+
return o;
303293
}
304294

305295
struct idset *drain_get (struct drain *drain)

0 commit comments

Comments
 (0)