コード例 #1
0
ファイル: abstract_node.py プロジェクト: thabaptiser/bxcommon
    def record_mem_stats(self, low_threshold: int, medium_threshold: int,
                         high_threshold: int):
        """
        When overridden, records identified memory stats and flushes them to std out
        :returns memory stats flush interval
        """
        total_memory = memory_utils.get_app_memory_usage()
        if total_memory > low_threshold:
            gc.collect()
            total_memory = memory_utils.get_app_memory_usage()
        self._record_mem_stats(total_memory > medium_threshold)

        return memory_statistics.flush_info(high_threshold)
コード例 #2
0
    def test_get_app_memory_usage(self):
        memory_usage = memory_utils.get_app_memory_usage()

        # verify that memory usage is reported in MB.
        # Expected to me less than 200 MB but greater than 1 MB
        self.assertLess(memory_usage, 200 * 1024 * 1024)
        self.assertGreater(memory_usage, 1 * 1024 * 1024)
コード例 #3
0
    def flush_info(self, threshold: int = sys.maxsize) -> int:
        node = self.node
        assert node is not None
        total_memory = memory_utils.get_app_memory_usage()
        node.dump_memory_usage(total_memory, threshold)

        return super(MemoryStatsService, self).flush_info(threshold)
コード例 #4
0
 async def process_request(self) -> JsonRpcResponse:
     tx_service = self.node.get_tx_service()
     cache_state = tx_service.get_cache_state_json()
     return self.ok({
         TOTAL_MEM_USAGE: stats_format.byte_count(memory_utils.get_app_memory_usage()),
         TOTAL_CACHED_TX: cache_state["tx_hash_to_contents_len"],
         TOTAL_CACHED_TX_SIZE: stats_format.byte_count(cache_state["total_tx_contents_size"])
     })
コード例 #5
0
ファイル: abstract_node.py プロジェクト: aspin/bxcommon
    def dump_memory_usage(self):
        total_mem_usage = memory_utils.get_app_memory_usage()

        if total_mem_usage >= self.next_report_mem_usage_bytes:
            node_size = memory_utils.get_detailed_object_size(self)
            memory_logger.statistics(
                "Application consumed {} bytes which is over set limit {} bytes. Detailed memory report: {}",
                total_mem_usage, self.next_report_mem_usage_bytes,
                json_utils.serialize(node_size))
            self.next_report_mem_usage_bytes = total_mem_usage + constants.MEMORY_USAGE_INCREASE_FOR_NEXT_REPORT_BYTES
コード例 #6
0
 def send_bdn_performance_stats(
         self, bdn_stats_interval: GatewayBdnPerformanceStatInterval):
     memory_utilization_mb = int(memory_utils.get_app_memory_usage() /
                                 constants.BYTE_TO_MB)
     msg_to_send = BdnPerformanceStatsMessage(
         bdn_stats_interval.start_time, bdn_stats_interval.end_time,
         bdn_stats_interval.new_blocks_received_from_blockchain_node,
         bdn_stats_interval.new_blocks_received_from_bdn,
         bdn_stats_interval.new_tx_received_from_blockchain_node,
         bdn_stats_interval.new_tx_received_from_bdn, memory_utilization_mb)
     self.enqueue_msg(msg_to_send)
コード例 #7
0
    def send_bdn_performance_stats(
            self, bdn_stats_interval: GatewayBdnPerformanceStatInterval):
        memory_utilization_mb = int(memory_utils.get_app_memory_usage() /
                                    constants.BYTE_TO_MB)
        bdn_stats_per_node = bdn_stats_interval.blockchain_node_to_bdn_stats
        if bdn_stats_per_node is None:
            bdn_stats_per_node = {}

        msg_to_send = BdnPerformanceStatsMessage(bdn_stats_interval.start_time,
                                                 bdn_stats_interval.end_time,
                                                 memory_utilization_mb,
                                                 bdn_stats_per_node)
        self.enqueue_msg(msg_to_send)
コード例 #8
0
    def get_info(self):
        # total_mem_usage is the peak mem usage fo the process (kilobytes on Linux, bytes on OS X)
        payload = dict(
            node_id=self.interval_data.node.opts.node_id,
            node_type=self.interval_data.node.opts.node_type,
            node_network_num=self.interval_data.node.opts.blockchain_network_num,
            node_address="%s:%d" % (
                self.interval_data.node.opts.external_ip,
                self.interval_data.node.opts.external_port
            ),
            total_mem_usage=memory_utils.get_app_memory_usage(),
            classes=self.interval_data.class_mem_stats
        )

        return payload
コード例 #9
0
    def get_info(self) -> Dict[str, Any]:
        # total_mem_usage is the peak mem usage fo the process (kilobytes on Linux, bytes on OS X)
        node = self.node
        assert node is not None
        payload = {
            "node_id": node.opts.node_id,
            "node_type": node.opts.node_type,
            "node_network_num": node.opts.blockchain_network_num,
            "node_address":
            f"{node.opts.external_ip}:{node.opts.external_port}",
            "total_mem_usage": memory_utils.get_app_memory_usage(),
            # pyre-ignore having some difficulty with subclassing generics
            "classes": self.interval_data.class_mem_stats,
        }

        return payload