You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

constants.py 2.9 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Copyright 2019 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Constants module for mindinsight settings."""
  16. import logging
  17. import math
  18. import os
  19. _DEFAULT_MAX_THREADS_COUNT = 15
  20. def _calc_default_max_processes_cnt():
  21. """Calc default processes count."""
  22. # We need to make sure every summary directory has a process to load data.
  23. min_cnt = _DEFAULT_MAX_THREADS_COUNT
  24. # Do not use too many processes to avoid system problems (eg. out of memory).
  25. max_cnt = 45
  26. used_cpu_ratio = 0.75
  27. cpu_count = os.cpu_count()
  28. if cpu_count is None:
  29. return min_cnt
  30. processes_cnt = math.floor(cpu_count * used_cpu_ratio)
  31. if processes_cnt < min_cnt:
  32. return min_cnt
  33. if processes_cnt > max_cnt:
  34. return max_cnt
  35. return processes_cnt
  36. ####################################
  37. # Global default settings.
  38. ####################################
  39. LOG_FORMAT = '[%(levelname)s] MI(%(process)d:%(thread)d,%(processName)s):%(asctime)s ' \
  40. '[%(filepath)s:%(lineno)d][%(sub_module)s] %(message)s'
  41. GUNICORN_ACCESS_FORMAT = "'%(t)s %(h)s <%(r)s> %(s)s %(b)s <%(f)s> <%(a)s> %(L)s '"
  42. LOG_LEVEL = logging.INFO
  43. # rotating max bytes, default is 50M
  44. LOG_ROTATING_MAXBYTES = 52428800
  45. # rotating backup count, default is 30
  46. LOG_ROTATING_BACKUPCOUNT = 30
  47. ####################################
  48. # Web default settings.
  49. ####################################
  50. HOST = '127.0.0.1'
  51. # Allow to support cross origin resource sharing(CORS) enable. Default is disable.
  52. # If enable CORS, `SUPPORT_REQUEST_METHODS` should enable 'OPTIONS' method.
  53. ENABLE_CORS = False
  54. SUPPORT_REQUEST_METHODS = {'POST', 'GET', 'PUT', 'DELETE'}
  55. # api prefix should not end with slash, correct format is /v1/url
  56. API_PREFIX = '/v1/mindinsight'
  57. ####################################
  58. # Datavisual default settings.
  59. ####################################
  60. MAX_THREADS_COUNT = _DEFAULT_MAX_THREADS_COUNT
  61. MAX_PROCESSES_COUNT = _calc_default_max_processes_cnt()
  62. MAX_TAG_SIZE_PER_EVENTS_DATA = 300
  63. DEFAULT_STEP_SIZES_PER_TAG = 500
  64. MAX_GRAPH_TAG_SIZE = 10
  65. MAX_TENSOR_TAG_SIZE = 6
  66. MAX_IMAGE_STEP_SIZE_PER_TAG = 10
  67. MAX_SCALAR_STEP_SIZE_PER_TAG = 1000
  68. MAX_GRAPH_STEP_SIZE_PER_TAG = 1
  69. MAX_HISTOGRAM_STEP_SIZE_PER_TAG = 50
  70. MAX_TENSOR_STEP_SIZE_PER_TAG = 20
  71. MAX_TENSOR_RESPONSE_DATA_SIZE = 100000