Remove calls to heapsize (#10432)
* update memorydb trait * use malloc_size_of instead of heapsize_of * use jemalloc as default allocator for parity client.
This commit is contained in:
@@ -65,7 +65,7 @@ pub const ETH_PROTOCOL: ProtocolId = *b"eth";
|
||||
pub const LIGHT_PROTOCOL: ProtocolId = *b"pip";
|
||||
|
||||
/// Determine warp sync status.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, MallocSizeOf)]
|
||||
pub enum WarpSync {
|
||||
/// Warp sync is enabled.
|
||||
Enabled,
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
use std::collections::{HashSet, VecDeque};
|
||||
use std::cmp;
|
||||
use heapsize::HeapSizeOf;
|
||||
use parity_util_mem::MallocSizeOf;
|
||||
use ethereum_types::H256;
|
||||
use rlp::{self, Rlp};
|
||||
use types::BlockNumber;
|
||||
@@ -60,7 +60,7 @@ macro_rules! debug_sync {
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, MallocSizeOf)]
|
||||
/// Downloader state
|
||||
pub enum State {
|
||||
/// No active downloads.
|
||||
@@ -113,6 +113,7 @@ impl From<rlp::DecoderError> for BlockDownloaderImportError {
|
||||
|
||||
/// Block downloader strategy.
|
||||
/// Manages state and block data for a block download process.
|
||||
#[derive(MallocSizeOf)]
|
||||
pub struct BlockDownloader {
|
||||
/// Which set of blocks to download
|
||||
block_set: BlockSet,
|
||||
@@ -223,11 +224,6 @@ impl BlockDownloader {
|
||||
self.state = State::Blocks;
|
||||
}
|
||||
|
||||
/// Returns used heap memory size.
|
||||
pub fn heap_size(&self) -> usize {
|
||||
self.blocks.heap_size() + self.round_parents.heap_size_of_children()
|
||||
}
|
||||
|
||||
/// Returns best imported block number.
|
||||
pub fn last_imported_block_number(&self) -> BlockNumber {
|
||||
self.last_imported_block
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use std::collections::{HashSet, HashMap, hash_map};
|
||||
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
|
||||
use heapsize::HeapSizeOf;
|
||||
use parity_util_mem::MallocSizeOf;
|
||||
use ethereum_types::H256;
|
||||
use triehash_ethereum::ordered_trie_root;
|
||||
use bytes::Bytes;
|
||||
@@ -26,21 +26,15 @@ use ethcore::verification::queue::kind::blocks::Unverified;
|
||||
use types::transaction::UnverifiedTransaction;
|
||||
use types::header::Header as BlockHeader;
|
||||
|
||||
known_heap_size!(0, HeaderId);
|
||||
malloc_size_of_is_0!(HeaderId);
|
||||
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
#[derive(MallocSizeOf)]
|
||||
pub struct SyncHeader {
|
||||
pub bytes: Bytes,
|
||||
pub header: BlockHeader,
|
||||
}
|
||||
|
||||
impl HeapSizeOf for SyncHeader {
|
||||
fn heap_size_of_children(&self) -> usize {
|
||||
self.bytes.heap_size_of_children()
|
||||
+ self.header.heap_size_of_children()
|
||||
}
|
||||
}
|
||||
|
||||
impl SyncHeader {
|
||||
pub fn from_rlp(bytes: Bytes) -> Result<Self, DecoderError> {
|
||||
let result = SyncHeader {
|
||||
@@ -52,6 +46,7 @@ impl SyncHeader {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(MallocSizeOf)]
|
||||
pub struct SyncBody {
|
||||
pub transactions_bytes: Bytes,
|
||||
pub transactions: Vec<UnverifiedTransaction>,
|
||||
@@ -85,16 +80,8 @@ impl SyncBody {
|
||||
}
|
||||
}
|
||||
|
||||
impl HeapSizeOf for SyncBody {
|
||||
fn heap_size_of_children(&self) -> usize {
|
||||
self.transactions_bytes.heap_size_of_children()
|
||||
+ self.transactions.heap_size_of_children()
|
||||
+ self.uncles_bytes.heap_size_of_children()
|
||||
+ self.uncles.heap_size_of_children()
|
||||
}
|
||||
}
|
||||
|
||||
/// Block data with optional body.
|
||||
#[derive(MallocSizeOf)]
|
||||
struct SyncBlock {
|
||||
header: SyncHeader,
|
||||
body: Option<SyncBody>,
|
||||
@@ -102,12 +89,6 @@ struct SyncBlock {
|
||||
receipts_root: H256,
|
||||
}
|
||||
|
||||
impl HeapSizeOf for SyncBlock {
|
||||
fn heap_size_of_children(&self) -> usize {
|
||||
self.header.heap_size_of_children() + self.body.heap_size_of_children()
|
||||
}
|
||||
}
|
||||
|
||||
fn unverified_from_sync(header: SyncHeader, body: Option<SyncBody>) -> Unverified {
|
||||
let mut stream = RlpStream::new_list(3);
|
||||
stream.append_raw(&header.bytes, 1);
|
||||
@@ -141,7 +122,7 @@ struct HeaderId {
|
||||
/// A collection of blocks and subchain pointers being downloaded. This keeps track of
|
||||
/// which headers/bodies need to be downloaded, which are being downloaded and also holds
|
||||
/// the downloaded blocks.
|
||||
#[derive(Default)]
|
||||
#[derive(Default, MallocSizeOf)]
|
||||
pub struct BlockCollection {
|
||||
/// Does this collection need block receipts.
|
||||
need_receipts: bool,
|
||||
@@ -399,16 +380,6 @@ impl BlockCollection {
|
||||
self.heads.len()
|
||||
}
|
||||
|
||||
/// Return used heap size.
|
||||
pub fn heap_size(&self) -> usize {
|
||||
self.heads.heap_size_of_children()
|
||||
+ self.blocks.heap_size_of_children()
|
||||
+ self.parents.heap_size_of_children()
|
||||
+ self.header_ids.heap_size_of_children()
|
||||
+ self.downloading_headers.heap_size_of_children()
|
||||
+ self.downloading_bodies.heap_size_of_children()
|
||||
}
|
||||
|
||||
/// Check if given block hash is marked as being downloaded.
|
||||
pub fn is_downloading(&self, hash: &H256) -> bool {
|
||||
self.downloading_headers.contains(hash) || self.downloading_bodies.contains(hash)
|
||||
|
||||
@@ -98,7 +98,7 @@ use std::collections::{HashSet, HashMap, BTreeMap};
|
||||
use std::cmp;
|
||||
use std::time::{Duration, Instant};
|
||||
use hash::keccak;
|
||||
use heapsize::HeapSizeOf;
|
||||
use parity_util_mem::MallocSizeOfExt;
|
||||
use futures::sync::mpsc as futures_mpsc;
|
||||
use api::Notification;
|
||||
use ethereum_types::{H256, U256};
|
||||
@@ -132,7 +132,7 @@ use self::propagator::SyncPropagator;
|
||||
use self::requester::SyncRequester;
|
||||
pub(crate) use self::supplier::SyncSupplier;
|
||||
|
||||
known_heap_size!(0, PeerInfo);
|
||||
malloc_size_of_is_0!(PeerInfo);
|
||||
|
||||
pub type PacketDecodeError = DecoderError;
|
||||
|
||||
@@ -179,7 +179,7 @@ const SNAPSHOT_DATA_TIMEOUT: Duration = Duration::from_secs(120);
|
||||
/// (so we might sent only to some part of the peers we originally intended to send to)
|
||||
const PRIORITY_TASK_DEADLINE: Duration = Duration::from_millis(100);
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, MallocSizeOf)]
|
||||
/// Sync state
|
||||
pub enum SyncState {
|
||||
/// Collecting enough peers to start syncing.
|
||||
@@ -273,7 +273,7 @@ pub enum PeerAsking {
|
||||
SnapshotData,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Copy, MallocSizeOf)]
|
||||
/// Block downloader channel.
|
||||
pub enum BlockSet {
|
||||
/// New blocks better than out best blocks
|
||||
@@ -585,6 +585,7 @@ enum PeerState {
|
||||
|
||||
/// Blockchain sync handler.
|
||||
/// See module documentation for more details.
|
||||
#[derive(MallocSizeOf)]
|
||||
pub struct ChainSync {
|
||||
/// Sync state
|
||||
state: SyncState,
|
||||
@@ -618,10 +619,12 @@ pub struct ChainSync {
|
||||
/// Enable ancient block downloading
|
||||
download_old_blocks: bool,
|
||||
/// Shared private tx service.
|
||||
#[ignore_malloc_size_of = "arc on dyn trait here seems tricky, ignoring"]
|
||||
private_tx_handler: Option<Arc<PrivateTxHandler>>,
|
||||
/// Enable warp sync.
|
||||
warp_sync: WarpSync,
|
||||
|
||||
#[ignore_malloc_size_of = "mpsc unmettered, ignoring"]
|
||||
status_sinks: Vec<futures_mpsc::UnboundedSender<SyncState>>
|
||||
}
|
||||
|
||||
@@ -677,10 +680,7 @@ impl ChainSync {
|
||||
num_active_peers: self.peers.values().filter(|p| p.is_allowed() && p.asking != PeerAsking::Nothing).count(),
|
||||
num_snapshot_chunks: self.snapshot.total_chunks(),
|
||||
snapshot_chunks_done: self.snapshot.done_chunks(),
|
||||
mem_used:
|
||||
self.new_blocks.heap_size()
|
||||
+ self.old_blocks.as_ref().map_or(0, |d| d.heap_size())
|
||||
+ self.peers.heap_size_of_children(),
|
||||
mem_used: self.malloc_size_of(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,10 @@ extern crate enum_primitive;
|
||||
extern crate macros;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate parity_util_mem;
|
||||
extern crate parity_util_mem as mem;
|
||||
#[macro_use]
|
||||
extern crate heapsize;
|
||||
extern crate parity_util_mem as malloc_size_of;
|
||||
#[macro_use]
|
||||
extern crate trace_time;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ pub enum ChunkType {
|
||||
Block(H256),
|
||||
}
|
||||
|
||||
#[derive(MallocSizeOf)]
|
||||
pub struct Snapshot {
|
||||
pending_state_chunks: Vec<H256>,
|
||||
pending_block_chunks: Vec<H256>,
|
||||
|
||||
@@ -23,7 +23,7 @@ use types::BlockNumber;
|
||||
|
||||
type NodeId = H512;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq, Clone, MallocSizeOf)]
|
||||
pub struct Stats {
|
||||
first_seen: BlockNumber,
|
||||
propagated_to: HashMap<NodeId, usize>,
|
||||
@@ -50,7 +50,7 @@ impl<'a> From<&'a Stats> for TransactionStats {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, MallocSizeOf)]
|
||||
pub struct TransactionsStats {
|
||||
pending_transactions: H256FastMap<Stats>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user