Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Event Logging to Add Command #4465

Closed
wants to merge 4 commits into from
Closed

Conversation

frrist
Copy link
Member

@frrist frrist commented Dec 7, 2017

License: MIT
Signed-off-by: ForrestWeston forrest@protocol.ai

@ghost ghost assigned frrist Dec 7, 2017
@ghost ghost added the status/in-progress In progress label Dec 7, 2017
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

My only worry would be performance but I'm pretty sure this won't be the bottleneck. However, would you mind running a small local before and after benchmark? E.g., add the go-ipfs git repo to an empty repo before and after (and then maybe try adding a large file).

@whyrusleeping
Copy link
Member

We really need benchmarks...

@frrist
Copy link
Member Author

frrist commented Dec 7, 2017

@Stebalien
time ipfs add -r go-ipfs
Before Changes (bbdbd0a):

  • 0.10user 0.07system 0:04.57elapsed 3%CPU (0avgtext+0avgdata 29340maxresident)k
    0inputs+0outputs (0major+2198minor)pagefaults 0swaps
  • 0.12user 0.06system 0:04.87elapsed 3%CPU (0avgtext+0avgdata 28816maxresident)k
    0inputs+0outputs (0major+2237minor)pagefaults 0swaps
  • 0.15user 0.03system 0:04.82elapsed 3%CPU (0avgtext+0avgdata 28732maxresident)k
    0inputs+0outputs (0major+2274minor)pagefaults 0swaps

After Changes (d84e5a2):

  • 0.09user 0.08system 0:04.83elapsed 3%CPU (0avgtext+0avgdata 29112maxresident)k
    0inputs+0outputs (0major+2204minor)pagefaults 0swaps
  • 0.12user 0.05system 0:04.70elapsed 3%CPU (0avgtext+0avgdata 26488maxresident)k
    0inputs+0outputs (0major+2231minor)pagefaults 0swaps
  • 0.12user 0.06system 0:04.65elapsed 3%CPU (0avgtext+0avgdata 26372maxresident)k
    0inputs+0outputs (0major+2235minor)pagefaults 0swaps

@whyrusleeping
Copy link
Member

Cool, doesnt appear to be any noticeable difference there.

@whyrusleeping
Copy link
Member

Could you post an image here of the tracing output that this generates?

@frrist
Copy link
Member Author

frrist commented Dec 8, 2017

Sorry it got cut off a bit, this on is from the above benchmarks.
add-go-ipfs

This is one from my bin/ dir
https://ipfs.io/ipfs/QmUMJCmHRQ2svFjWjXfiC5y5XCHG2qj4TvA4Jbz7XKFvaE/Selection_008.png

Also, its not shown in the screenshots, but you can view the tags (like filename) if you click the spans

@@ -153,112 +153,148 @@ func (adder Adder) add(reader io.Reader) (node.Node, error) {
}

func (adder *Adder) RootNode() (node.Node, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make sense as well? It feels cleaner, it compiles and the tests pass.

diff --git a/core/coreunix/add.go b/core/coreunix/add.go
index 516b76d44..090ecee27 100644
--- a/core/coreunix/add.go
+++ b/core/coreunix/add.go
@@ -152,40 +152,42 @@ func (adder Adder) add(reader io.Reader) (node.Node, error) {
        return balanced.BalancedLayout(params.New(chnk))
 }
 
-func (adder *Adder) RootNode() (node.Node, error) {
+func (adder *Adder) RootNode() (root node.Node, err error) {
        eip := log.EventBegin(adder.ctx, "RootNode")
-       defer eip.Done()
+       defer func() {
+               if root != nil {
+                       eip.Append(root.Cid())
+               }
+               if err != nil {
+                       eip.SetError(err)
+               }
+               eip.Done()
+       }()
        // for memoizing
-       if adder.root != nil {
-               eip.Append(adder.root.Cid())
-               return adder.root, nil
+       root = adder.root
+       if root != nil {
+               return root, nil
        }
 
        mr, err := adder.mfsRoot()
        if err != nil {
-               eip.SetError(err)
                return nil, err
        }
-       root, err := mr.GetValue().GetNode()
+       root, err = mr.GetValue().GetNode()
        if err != nil {
-               eip.SetError(err)
                return nil, err
        }
 
        // if not wrapping, AND one root file, use that hash as root.
        if !adder.Wrap && len(root.Links()) == 1 {
-               nd, err := root.Links()[0].GetNode(adder.ctx, adder.dagService)
+               root, err = root.Links()[0].GetNode(adder.ctx, adder.dagService)
                if err != nil {
-                       eip.SetError(err)
                        return nil, err
                }
-
-               root = nd
        }
 
        adder.root = root
-       eip.Append(root.Cid())
-       return root, err
+       return
 }

Copy link
Member

@Stebalien Stebalien Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with naming the return values for the purpose of accessing them from within the defer statement. However, I wouldn't use the implicit return feature (IMO, it was a mistake). How about:

diff --git a/core/coreunix/add.go b/core/coreunix/add.go
index 516b76d44..090ecee27 100644
--- a/core/coreunix/add.go
+++ b/core/coreunix/add.go
@@ -152,37 +152,38 @@ func (adder Adder) add(reader io.Reader) (node.Node, error) {
        return balanced.BalancedLayout(params.New(chnk))
 }
 
-func (adder *Adder) RootNode() (node.Node, error) {
+func (adder *Adder) RootNode() (root node.Node, err error) {
        eip := log.EventBegin(adder.ctx, "RootNode")
-       defer eip.Done()
+       defer func() {
+               if root != nil {
+                       eip.Append(root.Cid())
+               }
+               if err != nil {
+                       eip.SetError(err)
+               }
+               eip.Done()
+       }()
        // for memoizing
-       if adder.root != nil {
-               eip.Append(adder.root.Cid())
-               return adder.root, nil
+       if addr.root != nil {
+               return addr.root, nil
        }
 
        mr, err := adder.mfsRoot()
        if err != nil {
-               eip.SetError(err)
                return nil, err
        }
-       root, err := mr.GetValue().GetNode()
+       root, err = mr.GetValue().GetNode()
        if err != nil {
-               eip.SetError(err)
                return nil, err
        }
 
        // if not wrapping, AND one root file, use that hash as root.
        if !adder.Wrap && len(root.Links()) == 1 {
-               nd, err := root.Links()[0].GetNode(adder.ctx, adder.dagService)
+               root, err = root.Links()[0].GetNode(adder.ctx, adder.dagService)
                if err != nil {
-                       eip.SetError(err)
                        return nil, err
                }
-
-               root = nd
        }
 
        adder.root = root
-       eip.Append(root.Cid())
        return root, err
 }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, the implicit return thing was a terrible choice by the go team

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I can make these changes on the rest of the methods here too then. I am not sure if I should make that a separate commit or rebase. What would you prefer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either way, i'm not picky. Though I do appreciate smaller numbers of commits

return getBlocks(ctx, ks, s.blockstore, s.exchange)
}

func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f exchange.Fetcher) <-chan blocks.Block {
out := make(chan blocks.Block)
go func() {
defer logging.MaybeFinishEvent(ctx)
Copy link
Member Author

@frrist frrist Dec 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR needs to go first for this functionality.

@frrist frrist force-pushed the feat/coreunix/event-log branch 3 times, most recently from 1f8003a to aef5ab7 Compare December 21, 2017 23:01
@frrist frrist force-pushed the feat/coreunix/event-log branch 2 times, most recently from bd44804 to 28aa9e2 Compare January 9, 2018 23:15
@frrist frrist force-pushed the feat/coreunix/event-log branch 2 times, most recently from 9949fba to 3134df7 Compare January 18, 2018 23:10
@frrist
Copy link
Member Author

frrist commented Jan 18, 2018

Note: blocked until changes in go-log are bubbled up - CI will fail till then

@frrist frrist force-pushed the feat/coreunix/event-log branch 2 times, most recently from 5cdbf8d to 0215e8f Compare January 26, 2018 18:46
@Stebalien
Copy link
Member

Note: blocked until changes in go-log are bubbled up - CI will fail till then

Now that everything else has been unblocked, what exact changes do you still need (if any)?

@frrist
Copy link
Member Author

frrist commented Jan 31, 2018

@Stebalien we will need to gx publish the changes in go-log and update the version that go-ipfs uses (currently using 1.2.0).

The changes in go-log include instrumenting it with opentracing, as well as adding the DoneWithErr method and MaybeFinishEvent method (basically all the changes made to go-log in prs 8 - 16). I can start that process now.

CI fails because the aforementioned methods are missing from go-log and this branch uses them.

Changes Needed:
ipfs/go-log#17
#4637

frrist and others added 2 commits February 28, 2018 13:29
License: MIT
Signed-off-by: ForrestWeston <forrest@protocol.ai>
License: MIT
Signed-off-by: ForrestWeston <forrest@protocol.ai>
frrist and others added 2 commits February 28, 2018 13:49
Named return params and defer func to complete event

License: MIT
Signed-off-by: ForrestWeston <forrest@protocol.ai>
Contextual logging for async methods

License: MIT
Signed-off-by: ForrestWeston <forrest@protocol.ai>
@frrist
Copy link
Member Author

frrist commented Jan 22, 2019

Closing, will reopen when this becomes a priority -- I currently lack the bandwidth to push this forward.

@frrist frrist closed this Jan 22, 2019
@ghost ghost removed the status/in-progress In progress label Jan 22, 2019
@hacdias hacdias deleted the feat/coreunix/event-log branch May 9, 2023 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants