Skip to content

Commit 065ce86

Browse files
authored
Merge pull request #317 from carbonblack/job-worker-performance
Add more performant sensor spawner
2 parents b3662b2 + 1074dab commit 065ce86

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/cbapi/live_response_api.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -985,9 +985,21 @@ def _spawn_new_workers(self):
985985

986986
schedule_max = self._max_workers - len(self._job_workers)
987987

988-
sensors = [s for s in self._cb.select(Sensor) if s.id in self._unscheduled_jobs
989-
and s.id not in self._job_workers
990-
and s.status == "Online"]
988+
sensors = []
989+
990+
for sensor_id in self._unscheduled_jobs:
991+
sensor = self._cb.select(Sensor, sensor_id)
992+
if sensor_id in self._job_workers:
993+
log.debug("Skipping sensor {} already has a worker created".format(sensor_id))
994+
elif sensor.status == "Online":
995+
sensors.append(sensor)
996+
else:
997+
log.warn("Sensor {} could not be found or is not Online".format(sensor_id))
998+
999+
# Non performant original code
1000+
# sensors = [s for s in self._cb.select(Sensor) if s.id in self._unscheduled_jobs
1001+
# and s.id not in self._job_workers
1002+
# and s.status == "Online"]
9911003
sensors_to_schedule = sorted(sensors, key=lambda x: (
9921004
int(x.num_storefiles_bytes) + int(x.num_eventlog_bytes), x.next_checkin_time
9931005
))[:schedule_max]

0 commit comments

Comments
 (0)