Skip to content

Measure cache memory usage #19251

Closed

Description

@jdm

After #18676 merges we'll want to add support for measuring how much memory is in use by cached responses.

Activity

  1. added
    I-perf-bloat
    on Nov 16, 2017
  2. jdm commented on Nov 21, 2017

    @jdm
    MemberAuthor

    Required work:

  3. jdm commented on Nov 21, 2017

    @jdm
    MemberAuthor

    Run Servo with ./mach run --memory-profile 5 to print a memory profile every 5 seconds. If these changes are successful, there should be a new entry for the network cache.

  4. added
    E-more-complex
    on Nov 21, 2017
  5. olmanz commented on Nov 22, 2017

    @olmanz
    Contributor

    I would want to try this.

  6. added
    C-assigned
    on Nov 22, 2017
  7. jdm commented on Nov 22, 2017

    @jdm
    MemberAuthor

    Great! Please ask questions if anything is unclear.

  8. olmanz commented on Nov 23, 2017

    @olmanz
    Contributor

    After changing

    /// A memory cache.
    pub struct HttpCache {
        /// cached responses.
        entries: HashMap<CacheKey, Vec<CachedResource>>,
    }
    

    to

    /// A memory cache.
    #[derive(MallocSizeOf)]
    pub struct HttpCache {
        /// cached responses.
        entries: HashMap<CacheKey, Vec<CachedResource>>,
    }
    

    I get this error message during the build:

       Compiling net v0.0.1 (file:///home/olmanz/Schreibtisch/workspaces/Rust/servo/components/net)
    error: cannot find derive macro `MallocSizeOf` in this scope
      --> components/net/http_cache.rs:93:10
       |
    93 | #[derive(MallocSizeOf)]
       |          ^^^^^^^^^^^^
    
    error: aborting due to previous error
    
    error: Could not compile `net`.
    
    To learn more, run the command again with --verbose.
    Build FAILED in 0:00:08
    
    

    I already found out that there is a MallocSizeOf in the crate malloc_size_of. But when I import it with

    #[macro_use] extern crate malloc_size_of;
    use malloc_size_of::MallocSizeOf;
    

    it says

    
       Compiling net v0.0.1 (file:///home/olmanz/Schreibtisch/workspaces/Rust/servo/components/net)
    error[E0463]: can't find crate for `mallo_size_of`
      --> components/net/http_cache.rs:10:14
       |
    10 | #[macro_use] extern crate mallo_size_of;
       |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
    
    error: aborting due to previous error
    
    error: Could not compile `net`.
    
    To learn more, run the command again with --verbose.
    Build FAILED in 0:00:08
    

    What am I missing here?

  9. jdm commented on Nov 23, 2017

    @jdm
    MemberAuthor

    For one thing, that error message says mallo_size_of. However, be sure to add the crate to the Cargo.toml, as well.

  10. olmanz commented on Nov 24, 2017

    @olmanz
    Contributor

    add a new IpcReceiver argument to ResourceChannelManager::start that is used for listening to messages from the memory profiler (it must correspond with this sender)

    The sender is a IpcSender<ReporterRequest>, so the new argument must be of type IpcReceiver<ReporterRequest> if I understand correctly?

    use run_with_memory_reporting in the network code to register a memory reporter for that thread

    I see that run_with_memory_reporting must be called on profiler_chan here, but the function also takes some arguments (reporter_name, channel_for_reporter and msg), and I currently don't know where to get them inside the thread.

  11. olmanz commented on Nov 28, 2017

    @olmanz
    Contributor

    @jdm
    I'm still struggling with that part:
    use run_with_memory_reporting in the network code to register a memory reporter for that thread
    I searched for other instances where run_with_memory_reporting is used, e.g. in components/script/script_thread.rs and components/layout_thread/lib.rs.
    As I understand it, I have to call the function on profiler_chan in components/net/resource_thread.rs.
    But I'm not quite sure about the where to get the parameters that function should take. Can you give me a tip?

  12. jdm commented on Nov 28, 2017

    @jdm
    MemberAuthor

    The other parameters are:

    • the closure that will be executed - this is just the code that already exists, but turned into a closure
    • the reporter name - something like "network-cache-reporter"
    • a channel that will be used by the profiler thread to communicate with this code - I recommend creating a new channel, making ResourceChannelManager::start listen to the receiver, and passing the sender as this argument
    • a constructor for the message that will be sent on the channel - if the channel is only used for reporting, it should be enough to pass || () (which will provide a closure that returns a () value, meaning that the channel will only send and receive () values)
  13. olmanz commented on Dec 5, 2017

    @olmanz
    Contributor

    @jdm
    I changed the code block

    thread::Builder::new().name("ResourceManager".to_owned()).spawn(move || {
            let resource_manager = CoreResourceManager::new(
                user_agent, devtools_chan, profiler_chan
            );
    
            let mut channel_manager = ResourceChannelManager {
                resource_manager: resource_manager,
                config_dir: config_dir,
            };
            channel_manager.start(public_setup_port,
                                  private_setup_port);
    }).expect("Thread spawning failed");
    

    to this:

    thread::Builder::new().name("ResourceManager".to_owned()).spawn(move || {
            let resource_manager = CoreResourceManager::new(
                user_agent, devtools_chan, time_profiler_chan
            );
    
            let mut channel_manager = ResourceChannelManager {
                resource_manager: resource_manager,
                config_dir: config_dir,
            };
    
            let reporter_name = String::from("network-cache-reporter");
            let chan = channel();
            mem_profiler_chan.run_with_memory_reporting(|| {
                channel_manager.start(public_setup_port,
                                      private_setup_port);
            }, reporter_name, chan.0, || ());
    
        }).expect("Thread spawning failed");
    

    I'm passing || () now as recommended, but I get this error message now:

       Compiling net v0.0.1 (file:///home/olmanz/Schreibtisch/workspaces/Rust/servo/components/net)
    error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
      --> components/net/resource_thread.rs:88:27
       |
    88 |         mem_profiler_chan.run_with_memory_reporting(|| {
       |                           ^^^^^^^^^^^^^^^^^^^^^^^^^ expected closure that takes 1 argument
    ...
    91 |         }, reporter_name, chan.0, || ());
       |                                   -- takes 0 arguments
    
    error: aborting due to previous error
    
    error: Could not compile `net`.
    
    To learn more, run the command again with --verbose.
    Build FAILED in 0:00:10
    

    Do you have a suggestion what I can do to fix this error?

  14. jdm commented on Dec 5, 2017

    @jdm
    MemberAuthor

    Oh, you can use |_| () to pass a closure that ignores the argument.

  15. 10 remaining items

  16. jdm commented on Feb 14, 2018

    @jdm
    MemberAuthor

    @pandusonu2 Are you still working on this? Have you made any progress?

  17. pandusonu2 commented on Feb 15, 2018

    @pandusonu2
    Contributor

    @jdm Yeah! I'm trying to work to understand as much as possible. I refered to @olmanz branch and I understood the following changes have been implemented by him

    • Make HttpCache derive MallocSizeOf
      -- Include malloc_size_of and malloc_size_of_derive in Cargo.toml file
      -- Make CacheKey derive MallocSizeOf. Hence implement it for CacheKey, CacheResource, CacheResourceData
    • use run_with_memory_reporting in the network code to register a memory reporter for that thread
      -- For which there is addition of mem::ProfileChan in argument list of new_resource_threads()
      -- Include this in all occurences of new_resource_threads() and new_resource_thread()
    • [Current] add a new IpcReceiver argument to ResourceChannelManager::start that is used for listening to messages from the memory profiler (it must correspond with this sender)
      -- Added IpcReceiver in the argument list and also assert its id inside the loop

    I'm kinda getting errors at mem_profile_chan.run_with_memory_reporting(....)
    I know its easier to just ask you, but I'm new to Rust as a whole, so am trying to understand what exactly is happening 😓 So sorry that I'm taking too much time on this, if I don't get it done by this weekend, will definitely ask you 😃

  18. modal17 commented on Feb 18, 2018

    @modal17

    Heyo,

    Although I am not assigned, is it possible for me to look into this too?

  19. modal17 commented on Feb 20, 2018

    @modal17

    @pandusonu2 Are you working on this? Is it okay if I give it an attempt? @jdm

  20. jdm commented on Mar 5, 2018

    @jdm
    MemberAuthor

    @modal17 Did you delete a question that you previously asked? I swear I remember seeing one about what to measure.

  21. modal17 commented on Mar 9, 2018

    @modal17

    @jdm I did! I have the memory reporter displaying messages when running with --memory-profile At the moment, I'm slowly making the memory cache derive MallocSizeOf!

  22. added
    C-has-open-pr
    on Mar 26, 2018
  23. added a commit that references this issue on Mar 30, 2018
  24. added a commit that references this issue on Mar 31, 2018
    e9a21fa
  25. added a commit that references this issue on Apr 1, 2018
  26. added a commit that references this issue on Apr 1, 2018
    71ca1d9
  27. added a commit that references this issue on Apr 1, 2018
  28. added a commit that references this issue on Apr 2, 2018
    8f226f8
  29. added a commit that references this issue on Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-networkC-assignedC-has-open-prE-more-complexI-perf-bloat

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions