naeural-core 7.7.242__py3-none-any.whl → 7.7.243__py3-none-any.whl

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.
@@ -6,7 +6,7 @@ import traceback
6
6
 
7
7
  from collections import OrderedDict
8
8
 
9
- from time import time, sleep
9
+ from time import time, sleep, perf_counter
10
10
  from naeural_core import constants as ct
11
11
  from naeural_core import Logger
12
12
  from naeural_core.manager import Manager
@@ -245,142 +245,189 @@ class BusinessManager(Manager):
245
245
  current_instances = []
246
246
  self.set_loop_stage('2.bm.refresh._check_instances.get_current_jobs')
247
247
  all_jobs = self.get_current_jobs()
248
+ n_all_jobs = len(all_jobs)
249
+ self.P("Checking {} business plugin instances...".format(n_all_jobs))
250
+ total_start = perf_counter()
248
251
  for idx_job, (initiator_addr, initiator_id, modified_by_addr, modified_by_id, session_id, stream_name, signature, instance_id, upstream_config) in enumerate(all_jobs):
249
- obj_identification = (stream_name, signature, instance_id)
250
- instance_hash = self.log.hash_object(obj_identification, size=5)
251
- self._dct_hash_mappings[instance_hash] = obj_identification
252
- current_instances.append(instance_hash)
253
- if instance_hash not in self._dct_current_instances:
254
- self._dct_instance_hash_log[instance_hash] = {
255
- ct.PAYLOAD_DATA.INITIATOR_ID : initiator_id,
256
- ct.PAYLOAD_DATA.SESSION_ID : session_id,
257
- ct.PAYLOAD_DATA.SIGNATURE : signature,
258
- ct.PAYLOAD_DATA.STREAM_NAME : stream_name,
259
- ct.PAYLOAD_DATA.INSTANCE_ID : instance_id,
260
- }
261
-
262
- self.P(" * * * * Init biz plugin {}:{} * * * *".format(signature, instance_id), color='b')
263
- self.set_loop_stage('2.bm.refresh.get_class.{}:{}'.format(signature,instance_id))
264
- if 'update_monitor' in signature.lower():
265
- print('debug')
266
- _module_name, _class_name, _cls_def, _config_dict = self._get_module_name_and_class(
267
- locations=ct.PLUGIN_SEARCH.LOC_BIZ_PLUGINS,
268
- name=signature,
269
- suffix=ct.PLUGIN_SEARCH.SUFFIX_BIZ_PLUGINS,
270
- verbose=0,
271
- safety_check=True, # perform safety check on custom biz plugins
272
- safe_locations=ct.PLUGIN_SEARCH.SAFE_BIZ_PLUGINS,
273
- safe_imports=ct.PLUGIN_SEARCH.SAFE_BIZ_IMPORTS
274
- )
252
+ iter_start = perf_counter()
253
+ get_class_s = 0.0
254
+ instantiate_s = 0.0
255
+ start_thread_s = 0.0
256
+ update_config_s = 0.0
257
+ is_new_instance = False
258
+ try:
259
+ obj_identification = (stream_name, signature, instance_id)
260
+ instance_hash = self.log.hash_object(obj_identification, size=5)
261
+ self._dct_hash_mappings[instance_hash] = obj_identification
262
+ current_instances.append(instance_hash)
263
+ if instance_hash not in self._dct_current_instances:
264
+ is_new_instance = True
265
+ self._dct_instance_hash_log[instance_hash] = {
266
+ ct.PAYLOAD_DATA.INITIATOR_ID : initiator_id,
267
+ ct.PAYLOAD_DATA.SESSION_ID : session_id,
268
+ ct.PAYLOAD_DATA.SIGNATURE : signature,
269
+ ct.PAYLOAD_DATA.STREAM_NAME : stream_name,
270
+ ct.PAYLOAD_DATA.INSTANCE_ID : instance_id,
271
+ }
275
272
 
276
- self.set_loop_stage('2.bm.refresh.check_class.{}:{}'.format(signature,instance_id))
277
-
278
- if _cls_def is None:
279
- self._dct_current_instances[instance_hash] = None
280
- msg = "Error loading business plugin <{}:{}> - No code/script defined.".format(signature, instance_id)
281
- self.P(msg + " on stream {}".format(stream_name), color='r')
282
- self._create_notification(
283
- notif=ct.STATUS_TYPE.STATUS_EXCEPTION,
284
- msg=msg,
285
- stream_name=stream_name,
286
- info="No code/script defined for business plugin '{}' in {} or plugin is invalid (node {})".format(
287
- signature, ct.PLUGIN_SEARCH.LOC_BIZ_PLUGINS, "is currently SECURED" if self.owner.is_secured else "is currently UNSECURED!"
288
- )
273
+ self.P(
274
+ " * * * * Init biz plugin #{}/{} {}:{} * * * *".format(
275
+ idx_job + 1, n_all_jobs, signature, instance_id
276
+ ),
277
+ color='b'
289
278
  )
290
- continue
291
- #endif
292
-
293
- self.comm_shared_memory['payloads'][instance_hash] = deque(maxlen=1000)
294
- self.comm_shared_memory['commands'][instance_hash] = deque(maxlen=1000)
279
+ self.set_loop_stage('2.bm.refresh.get_class.{}:{}'.format(signature,instance_id))
280
+ if 'update_monitor' in signature.lower():
281
+ print('debug')
282
+ get_class_start = perf_counter()
283
+ _module_name, _class_name, _cls_def, _config_dict = self._get_module_name_and_class(
284
+ locations=ct.PLUGIN_SEARCH.LOC_BIZ_PLUGINS,
285
+ name=signature,
286
+ suffix=ct.PLUGIN_SEARCH.SUFFIX_BIZ_PLUGINS,
287
+ verbose=0,
288
+ safety_check=True, # perform safety check on custom biz plugins
289
+ safe_locations=ct.PLUGIN_SEARCH.SAFE_BIZ_PLUGINS,
290
+ safe_imports=ct.PLUGIN_SEARCH.SAFE_BIZ_IMPORTS
291
+ )
292
+ get_class_s = perf_counter() - get_class_start
295
293
 
296
- try:
297
- self.set_loop_stage('2.bm.refresh.call_class.{}:{}:{}'.format(stream_name, signature, instance_id))
298
- self.shmem['__set_loop_stage_func'] = self.set_loop_stage
299
- # debug when configuring a plugin
300
- debug_config_changes = self.config_data.get('PLUGINS_DEBUG_CONFIG_CHANGES', False) # Ugly but needed
301
- # end debug
294
+ self.set_loop_stage('2.bm.refresh.check_class.{}:{}'.format(signature,instance_id))
302
295
 
303
- _module_version = _config_dict.get('MODULE_VERSION', '0.0.0')
304
-
305
- plugin = _cls_def(
306
- log=self.log,
307
- global_shmem=self.shmem, # this SHOULD NOT be used for inter-plugin mem access
308
- plugins_shmem=self.plugins_shmem,
309
- stream_id=stream_name,
310
- signature=signature,
311
- default_config=_config_dict,
312
- upstream_config=upstream_config,
313
- environment_variables=self._environment_variables,
314
- initiator_id=initiator_id,
315
- initiator_addr=initiator_addr,
316
- session_id=session_id,
317
- threaded_execution_chain=self._run_on_threads,
318
- payloads_deque=self.comm_shared_memory['payloads'][instance_hash],
319
- commands_deque=self.comm_shared_memory['commands'][instance_hash],
320
- ee_ver=self.owner.__version__,
321
- runs_in_docker=self.owner.runs_in_docker,
322
- docker_branch=self.owner.docker_source,
323
- debug_config_changes=debug_config_changes,
324
- version=_module_version,
325
- pipelines_view_function=self.owner.get_pipelines_view,
326
- pipeline_use_local_comms_only=self._dct_config_streams[stream_name].get(ct.CONFIG_STREAM.K_USE_LOCAL_COMMS_ONLY, False),
327
- )
328
- if plugin.cfg_runs_only_on_supervisor_node:
329
- if not self.is_supervisor_node:
330
- self.P(
331
- "Plugin {}:{} runs ONLY on supervisor node. Skipping.".format(signature, instance_id),
332
- color='r', boxed=True,
296
+ if _cls_def is None:
297
+ self._dct_current_instances[instance_hash] = None
298
+ msg = "Error loading business plugin <{}:{}> - No code/script defined.".format(signature, instance_id)
299
+ self.P(msg + " on stream {}".format(stream_name), color='r')
300
+ self._create_notification(
301
+ notif=ct.STATUS_TYPE.STATUS_EXCEPTION,
302
+ msg=msg,
303
+ stream_name=stream_name,
304
+ info="No code/script defined for business plugin '{}' in {} or plugin is invalid (node {})".format(
305
+ signature, ct.PLUGIN_SEARCH.LOC_BIZ_PLUGINS, "is currently SECURED" if self.owner.is_secured else "is currently UNSECURED!"
333
306
  )
334
- plugin = None
335
- # continue
336
- else:
337
- self.P("Plugin {}:{} runs only on supervisor node. Running.".format(signature, instance_id), color='g')
338
- # endif runs only on supervisor node
339
- self.set_loop_stage('2.bm.refresh.new_instance_done: {}:{}:{}'.format(stream_name, signature, instance_id))
340
- except Exception as exc:
341
- plugin = None
342
- trace = traceback.format_exc()
343
- msg = "Plugin init FAILED for business plugin {} instance {}".format(signature, instance_id)
344
- info = str(exc)
345
- if "validating" not in info:
346
- info += '\n' + trace
347
- self.P(msg + ': ' + info, color='r')
348
- self._create_notification(
349
- notif=ct.STATUS_TYPE.STATUS_EXCEPTION,
350
- msg=msg,
351
- signature=signature,
352
- instance_id=instance_id,
353
- stream_name=stream_name,
354
- info=info,
355
- displayed=True,
356
- )
357
- #end try-except
307
+ )
308
+ continue
309
+ #endif
310
+
311
+ self.comm_shared_memory['payloads'][instance_hash] = deque(maxlen=1000)
312
+ self.comm_shared_memory['commands'][instance_hash] = deque(maxlen=1000)
313
+
314
+ try:
315
+ self.set_loop_stage('2.bm.refresh.call_class.{}:{}:{}'.format(stream_name, signature, instance_id))
316
+ self.shmem['__set_loop_stage_func'] = self.set_loop_stage
317
+ # debug when configuring a plugin
318
+ debug_config_changes = self.config_data.get('PLUGINS_DEBUG_CONFIG_CHANGES', False) # Ugly but needed
319
+ # end debug
320
+
321
+ _module_version = _config_dict.get('MODULE_VERSION', '0.0.0')
322
+
323
+ instantiate_start = perf_counter()
324
+ plugin = _cls_def(
325
+ log=self.log,
326
+ global_shmem=self.shmem, # this SHOULD NOT be used for inter-plugin mem access
327
+ plugins_shmem=self.plugins_shmem,
328
+ stream_id=stream_name,
329
+ signature=signature,
330
+ default_config=_config_dict,
331
+ upstream_config=upstream_config,
332
+ environment_variables=self._environment_variables,
333
+ initiator_id=initiator_id,
334
+ initiator_addr=initiator_addr,
335
+ session_id=session_id,
336
+ threaded_execution_chain=self._run_on_threads,
337
+ payloads_deque=self.comm_shared_memory['payloads'][instance_hash],
338
+ commands_deque=self.comm_shared_memory['commands'][instance_hash],
339
+ ee_ver=self.owner.__version__,
340
+ runs_in_docker=self.owner.runs_in_docker,
341
+ docker_branch=self.owner.docker_source,
342
+ debug_config_changes=debug_config_changes,
343
+ version=_module_version,
344
+ pipelines_view_function=self.owner.get_pipelines_view,
345
+ pipeline_use_local_comms_only=self._dct_config_streams[stream_name].get(ct.CONFIG_STREAM.K_USE_LOCAL_COMMS_ONLY, False),
346
+ )
347
+ instantiate_s = perf_counter() - instantiate_start
348
+ if plugin.cfg_runs_only_on_supervisor_node:
349
+ if not self.is_supervisor_node:
350
+ self.P(
351
+ "Plugin {}:{} runs ONLY on supervisor node. Skipping.".format(signature, instance_id),
352
+ color='r', boxed=True,
353
+ )
354
+ plugin = None
355
+ # continue
356
+ else:
357
+ self.P("Plugin {}:{} runs only on supervisor node. Running.".format(signature, instance_id), color='g')
358
+ # endif runs only on supervisor node
359
+ self.set_loop_stage('2.bm.refresh.new_instance_done: {}:{}:{}'.format(stream_name, signature, instance_id))
360
+ except Exception as exc:
361
+ plugin = None
362
+ trace = traceback.format_exc()
363
+ msg = "Plugin init FAILED for business plugin {} instance {}".format(signature, instance_id)
364
+ info = str(exc)
365
+ if "validating" not in info:
366
+ info += '\n' + trace
367
+ self.P(msg + ': ' + info, color='r')
368
+ self._create_notification(
369
+ notif=ct.STATUS_TYPE.STATUS_EXCEPTION,
370
+ msg=msg,
371
+ signature=signature,
372
+ instance_id=instance_id,
373
+ stream_name=stream_name,
374
+ info=info,
375
+ displayed=True,
376
+ )
377
+ #end try-except
358
378
 
359
- self._dct_current_instances[instance_hash] = plugin
360
- self.__maybe_register_special_plugin_instance_hash(instance_hash=instance_hash, signature=signature)
379
+ self._dct_current_instances[instance_hash] = plugin
380
+ self.__maybe_register_special_plugin_instance_hash(instance_hash=instance_hash, signature=signature)
361
381
 
362
- if plugin is None:
363
- continue
382
+ if plugin is None:
383
+ continue
364
384
 
365
- self.P("New plugin instance {} added for exec.".format(plugin), color='g')
366
- if self._run_on_threads:
367
- plugin.start_thread()
368
- #endif new instance
369
- else:
370
- # I do have the instance, I just need to modify the config
371
- plugin = self._dct_current_instances[instance_hash]
372
- if plugin is not None:
373
- # next we need to check if the config has changed and handle also the particular
374
- # case when the plugin just received a INSTANCE_COMMAND
375
- plugin.maybe_update_instance_config(
376
- upstream_config=upstream_config,
377
- session_id=session_id,
378
- modified_by_addr=modified_by_addr,
379
- modified_by_id=modified_by_id,
380
- )
381
- self.set_loop_stage('2.bm.refresh.maybe_update_instance_config.DONE: {}:{}:{}'.format(stream_name, signature, instance_id))
385
+ self.P("New plugin instance {} added for exec.".format(plugin), color='g')
386
+ if self._run_on_threads:
387
+ start_thread_start = perf_counter()
388
+ plugin.start_thread()
389
+ start_thread_s = perf_counter() - start_thread_start
390
+ #endif new instance
391
+ else:
392
+ # I do have the instance, I just need to modify the config
393
+ plugin = self._dct_current_instances[instance_hash]
394
+ if plugin is not None:
395
+ # next we need to check if the config has changed and handle also the particular
396
+ # case when the plugin just received a INSTANCE_COMMAND
397
+ update_config_start = perf_counter()
398
+ plugin.maybe_update_instance_config(
399
+ upstream_config=upstream_config,
400
+ session_id=session_id,
401
+ modified_by_addr=modified_by_addr,
402
+ modified_by_id=modified_by_id,
403
+ )
404
+ update_config_s = perf_counter() - update_config_start
405
+ self.set_loop_stage('2.bm.refresh.maybe_update_instance_config.DONE: {}:{}:{}'.format(stream_name, signature, instance_id))
406
+ #endif
382
407
  #endif
383
- #endif
408
+ finally:
409
+ # Done to avoid spam logs - only log new instances
410
+ if is_new_instance:
411
+ iter_total_s = perf_counter() - iter_start
412
+ total_elapsed_s = perf_counter() - total_start
413
+ self.P(
414
+ " START Plugin {}/{} {}:{} new={} total={:.2f}s get_class={:.2f}s init={:.2f}s start_thread={:.2f}s update_cfg={:.2f}s (ALL={:.2f}s)".format(
415
+ idx_job + 1,
416
+ n_all_jobs,
417
+ signature,
418
+ instance_id,
419
+ is_new_instance,
420
+ iter_total_s,
421
+ get_class_s,
422
+ instantiate_s,
423
+ start_thread_s,
424
+ update_config_s,
425
+ total_elapsed_s,
426
+ ),
427
+ boxed=True
428
+ )
429
+ # endif is new instance
430
+ # end try-finally
384
431
 
385
432
  return current_instances
386
433
 
@@ -653,4 +700,3 @@ class BusinessManager(Manager):
653
700
  #endfor
654
701
  self.log.stop_timer('execute_all_business_plugins', skip_first_timing=False)
655
702
  return
656
-
naeural_core/main/ver.py CHANGED
@@ -1,4 +1,4 @@
1
- __VER__ = '7.7.242'
1
+ __VER__ = '7.7.243'
2
2
 
3
3
 
4
4
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: naeural_core
3
- Version: 7.7.242
3
+ Version: 7.7.243
4
4
  Summary: Ratio1 Core is the backbone of the Ratio1 Edge Protocol.
5
5
  Project-URL: Homepage, https://github.com/Ratio1/naeural_core
6
6
  Project-URL: Bug Tracker, https://github.com/Ratio1/naeural_core/issues
@@ -5,7 +5,7 @@ naeural_core/decentrai_object.py,sha256=pw-NRmlQRAzvUVFfh1xTJdj1Ltd2Y-UVrpompriU
5
5
  naeural_core/manager.py,sha256=fMyVjM2UXQ0LxHE33z1t9AQxmxn68uUsu9EseK5zqDo,3406
6
6
  naeural_core/bc/__init__.py,sha256=Su7YuJjTPI1P3a6L8WGRqW2YvDADyLMYSipcZognAEM,176
7
7
  naeural_core/business/__init__.py,sha256=9boWpUoISx1OkCftejQXaw-sqv6M88LLt7CLNZjdnfU,46
8
- naeural_core/business/business_manager.py,sha256=UfRNTjfr3ZfUAfjedyq6AqdovJDTtGrrRUN_L3uvBic,26858
8
+ naeural_core/business/business_manager.py,sha256=ZPnw19TH9ycsVeVL_mtWs7rC9OSQn7nMCXZMAisgqTo,28815
9
9
  naeural_core/business/utils.py,sha256=ykl7d1snVldTPR7LyDjSSPL4LOGag0pgkRfOnGZXJKg,15765
10
10
  naeural_core/business/base/__init__.py,sha256=OEhyheZKcCk2GafJuO6bDVi1ph1pZyW0A8wan_SuesA,270
11
11
  naeural_core/business/base/base_plugin_biz.py,sha256=KlMD1c50meTWYHoS-GaXeICWhvNhsXiXgaYpMfQCFn4,74532
@@ -345,7 +345,7 @@ naeural_core/main/geoloc.py,sha256=TEqyuNzpVqZSBCo0OOrpHYncIsHSClvRt28hgvxJ35o,2
345
345
  naeural_core/main/main_loop_data_handler.py,sha256=hABB65OUBhtur3rd2mYsEhdAc54jVILzybrvxml5h0s,13815
346
346
  naeural_core/main/net_mon.py,sha256=qlyo1fqTeQy_M9VfJOxon_PBbQat0QO9Zbu_93FMbLc,88144
347
347
  naeural_core/main/orchestrator.py,sha256=0FhxLgpJN9Wjw1L7Ojx4Mi0P82u8dNDRTfUdqGh0Tqs,70626
348
- naeural_core/main/ver.py,sha256=Ga9K1mXR6U7fDBbh2_lozzdOHGPe7E40abF2oYh_SWI,335
348
+ naeural_core/main/ver.py,sha256=Ej_BKrKSBFiPw5XvW16axNWnd5gnXYHCBK7jdTY70Sg,335
349
349
  naeural_core/main/orchestrator_mixins/__init__.py,sha256=MNleg48vdlqsyAR8Vamjl4ahG2jwCH5kLbQN5CfU57E,149
350
350
  naeural_core/main/orchestrator_mixins/managers_init.py,sha256=sQVqpr99a5WP9HCloYCyaWDW5J3IypEImlf703bqTF4,6692
351
351
  naeural_core/main/orchestrator_mixins/utils.py,sha256=jMa0uStVNLQmp0VhNMRvfBDjo387ORLlUVLthRNBKqc,1866
@@ -555,7 +555,7 @@ naeural_core/utils/tracing/onnx/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
555
555
  naeural_core/utils/tracing/onnx/base_trt_scripter.py,sha256=1FelEBo7JGsc8hbJ3sevzxnM-J61nvBHz6L1VLpZrVc,2043
556
556
  naeural_core/utils/tracing/onnx/utils.py,sha256=IKmqUWakrMWn34uJvbRjNLacdszD8jkkQBFPUhgJtOQ,5618
557
557
  naeural_core/utils/web_app/favicon.ico,sha256=zU6-Jxx4ol1A9FJvcQELYV9DiqwqyvjPS89xQybZE74,15406
558
- naeural_core-7.7.242.dist-info/METADATA,sha256=f7kZ1SrW7zJuC9edJQDUX9cBCV_bOTTxYVcpC4UnBkU,6522
559
- naeural_core-7.7.242.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
560
- naeural_core-7.7.242.dist-info/licenses/LICENSE,sha256=SPHPWjOdAUUUUI020nI5VNCtFjmTOlJpi1cZxyB3gKo,11339
561
- naeural_core-7.7.242.dist-info/RECORD,,
558
+ naeural_core-7.7.243.dist-info/METADATA,sha256=QOw-MVuhPkWufArzSVPVC9SlMIstJ7CkD72AAPG0xl0,6522
559
+ naeural_core-7.7.243.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
560
+ naeural_core-7.7.243.dist-info/licenses/LICENSE,sha256=SPHPWjOdAUUUUI020nI5VNCtFjmTOlJpi1cZxyB3gKo,11339
561
+ naeural_core-7.7.243.dist-info/RECORD,,