@andersbakken/fisk 4.0.55 → 4.0.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,6 +42,12 @@ const Constants = {
42
42
  get JSON() {
43
43
  return 5;
44
44
  },
45
+ get AcquireSlot() {
46
+ return 6;
47
+ },
48
+ get ReleaseLocalSlot() {
49
+ return 7;
50
+ },
45
51
  // daemon codes
46
52
  get CppSlotAcquired() {
47
53
  return 10;
@@ -51,6 +57,9 @@ const Constants = {
51
57
  },
52
58
  get JSONResponse() {
53
59
  return 12;
60
+ },
61
+ get LocalSlotAcquired() {
62
+ return 13;
54
63
  }
55
64
  };
56
65
 
@@ -208,6 +217,12 @@ class Compile extends EventEmitter__default["default"] {
208
217
  case Constants.ReleaseCompileSlot:
209
218
  emit("releaseCompileSlot");
210
219
  continue;
220
+ case Constants.AcquireSlot:
221
+ emit("acquireSlot");
222
+ continue;
223
+ case Constants.ReleaseLocalSlot:
224
+ emit("releaseLocalSlot");
225
+ continue;
211
226
  case Constants.JSON:
212
227
  if (available < 5) {
213
228
  break;
@@ -3334,6 +3349,16 @@ class Slots extends EventEmitter__default["default"] {
3334
3349
  console.log("Slots created", this.toString());
3335
3350
  }
3336
3351
  }
3352
+ tryAcquire(id, data) {
3353
+ if (this.used.size < this.count) {
3354
+ this.used.set(id, data);
3355
+ if (this.debug) {
3356
+ console.log("tryAcquire succeeded", id, data, this.toString());
3357
+ }
3358
+ return true;
3359
+ }
3360
+ return false;
3361
+ }
3337
3362
  acquire(id, data, cb) {
3338
3363
  if (this.used.size < this.count) {
3339
3364
  this.used.set(id, data);
@@ -4118,6 +4143,8 @@ Options:
4118
4143
  --socket=PATH Unix socket path (default: ~/.cache/fisk/daemon/socket)
4119
4144
  --cpp-slots=N Preprocess slot count (default: cpus * 2)
4120
4145
  --slots=N Compile slot count (default: cpus)
4146
+ --local-slots=N Local compile slot count (default: 0, disabled)
4147
+ --local-slots-max-load=N Max system load average (1-min) to allow local compiles (default: 0, no limit)
4121
4148
  --cache-dir=PATH Cache directory (default: ~/.cache/fisk/daemon)
4122
4149
 
4123
4150
  Config files: ~/.config/fisk/daemon.conf, /etc/xdg/fisk/daemon.conf
@@ -4153,15 +4180,34 @@ server.on("error", (err) => {
4153
4180
  });
4154
4181
  const cppSlots = new Slots(option.int("cpp-slots", Math.max(os__default["default"].cpus().length * 2, 1)), "cpp", debug);
4155
4182
  const compileSlots = new Slots(option.int("slots", Math.max(os__default["default"].cpus().length, 1)), "compile", debug);
4183
+ const localSlotCount = option.int("local-slots", 0);
4184
+ const localSlots = new Slots(localSlotCount, "local", debug);
4185
+ const localSlotsMaxLoad = option("local-slots-max-load") || 0;
4186
+ function canAcquireLocalSlot() {
4187
+ if (localSlotCount <= 0) {
4188
+ return false;
4189
+ }
4190
+ if (localSlotsMaxLoad > 0) {
4191
+ const loadAvg = os__default["default"].loadavg()[0];
4192
+ if (loadAvg > localSlotsMaxLoad) {
4193
+ if (debug) {
4194
+ console.log(`Local slot denied: load ${loadAvg.toFixed(2)} > max ${localSlotsMaxLoad}`);
4195
+ }
4196
+ return false;
4197
+ }
4198
+ }
4199
+ return true;
4200
+ }
4156
4201
  server.on("compile", (compile) => {
4157
4202
  compile.on("dumpSlots", () => {
4158
- const ret = { cpp: cppSlots.dump(), compile: compileSlots.dump() };
4203
+ const ret = { cpp: cppSlots.dump(), compile: compileSlots.dump(), local: localSlots.dump() };
4159
4204
  if (debug) {
4160
4205
  console.log("sending dump", ret);
4161
4206
  }
4162
4207
  compile.send(ret);
4163
4208
  });
4164
4209
  let requestedCppSlot = false;
4210
+ let requestedLocalSlot = false;
4165
4211
  compile.on("acquireCppSlot", () => {
4166
4212
  if (debug) {
4167
4213
  console.log("acquireCppSlot");
@@ -4205,6 +4251,38 @@ server.on("compile", (compile) => {
4205
4251
  compileSlots.release(compile.id);
4206
4252
  }
4207
4253
  });
4254
+ compile.on("acquireSlot", () => {
4255
+ if (debug) {
4256
+ console.log("acquireSlot");
4257
+ }
4258
+ if (canAcquireLocalSlot() && localSlots.tryAcquire(compile.id, { pid: compile.pid })) {
4259
+ if (debug) {
4260
+ console.log("acquireSlot -> local slot granted");
4261
+ }
4262
+ requestedLocalSlot = true;
4263
+ compile.send(Constants.LocalSlotAcquired);
4264
+ }
4265
+ else {
4266
+ if (debug) {
4267
+ console.log("acquireSlot -> falling back to cpp slot");
4268
+ }
4269
+ assert__default["default"](!requestedCppSlot);
4270
+ requestedCppSlot = true;
4271
+ cppSlots.acquire(compile.id, { pid: compile.pid }, () => {
4272
+ compile.send(Constants.CppSlotAcquired);
4273
+ });
4274
+ }
4275
+ });
4276
+ compile.on("releaseLocalSlot", () => {
4277
+ if (debug) {
4278
+ console.log("releaseLocalSlot");
4279
+ }
4280
+ assert__default["default"](requestedLocalSlot);
4281
+ if (requestedLocalSlot) {
4282
+ requestedLocalSlot = false;
4283
+ localSlots.release(compile.id);
4284
+ }
4285
+ });
4208
4286
  compile.on("error", (err) => {
4209
4287
  if (debug) {
4210
4288
  console.error("Got error from fiskc", compile.id, compile.pid, err);
@@ -4217,6 +4295,10 @@ server.on("compile", (compile) => {
4217
4295
  requestedCompileSlot = false;
4218
4296
  compileSlots.release(compile.id);
4219
4297
  }
4298
+ if (requestedLocalSlot) {
4299
+ requestedLocalSlot = false;
4300
+ localSlots.release(compile.id);
4301
+ }
4220
4302
  });
4221
4303
  compile.on("end", () => {
4222
4304
  if (debug) {
@@ -4230,6 +4312,10 @@ server.on("compile", (compile) => {
4230
4312
  requestedCompileSlot = false;
4231
4313
  compileSlots.release(compile.id);
4232
4314
  }
4315
+ if (requestedLocalSlot) {
4316
+ requestedLocalSlot = false;
4317
+ localSlots.release(compile.id);
4318
+ }
4233
4319
  });
4234
4320
  });
4235
4321
  process.on("exit", () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andersbakken/fisk",
3
- "version": "4.0.55",
3
+ "version": "4.0.56",
4
4
  "description": "Fisk, a distributed compile system",
5
5
  "scripts": {
6
6
  "lint": "eslint . --ext .ts",