git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
From: Takuto Ikuta <tikuta@chromium.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v3] fetch-pack.c: use oidset to check existence of loose object
Date: Sat, 10 Mar 2018 22:19:15 +0900
Message-ID: <CALNjmMqBbZTFVRnc__wewWy3808n9J9xfgu8ZH-FWyWJKvqb9w@mail.gmail.com> (raw)
In-Reply-To: <xmqq606558k2.fsf@gitster-ct.c.googlers.com>

2018-03-10 3:00 GMT+09:00 Junio C Hamano <gitster@pobox.com>:
> Takuto Ikuta <tikuta@chromium.org> writes:
>
>> Yes, I just wanted to say 'git fetch' invokes fetch-pack.
>> fetch-pack is skipped when running git fetch repeatedly while
>> remote has no update by quickfetch. So I disabled it to see the
>> performance of fetch-pack. In chromium repository, master branch
>> is updated several times in an hour, so git fetch invokes fetch-pack
>> in such frequency.
>
> I do understand that if you run "git fetch" against the same place
> in quick succession three times, the first one may cost a lot (not
> just that it has to do the everything_local() computation that you
> care about, it also has to actually do the network transfer), while
> the second and third ones that are done before anything new happens
> on the other end will not involve everything_local() overhead thanks
> to quickfetch.
>
> A "fetch" that is run against a remote that has nothing new, but
> still triggers everything_local() only because quickfetch is
> disabled, is an artificial case that has no relevance to the real
> world, I suspect, because the quickfetch optimization is to solve
> the "there is nothing to be done, still do_fetch_pack() spends so
> much cycles only to realize that it does not have anything to do,
> why?" issue.
>

I changed not to say "disabling quickfetch" in v5 description.
Actually, I'd like to take several stats on linux because the perf difference
is small and it can be affected by network and quickfetch.

> Isn't running the "git fetch" command with the "--dry-run" option
> many times in quick succession a lot closer to what you really want
> to measure, I wonder?  That way, your first fetch won't be touching
> the state of the local side to affect your second and subsequent
> fetches.
>

Looks no? Even when I use --dry-run, second run did not invoke fetch-pack.

>>> In any case, do_fetch_pack() tries to see if all of the tip commits
>>> we are going to fetch exist locally, so when you are trying a fetch
>>> that grabs huge number of refs (by the way, it means that the first
>>> sentence of the proposed log message is not quite true---it is "When
>>> fetching a large number of refs", as it does not matter how many
>>> refs _we_ have, no?), everything_local() ends up making repeated
>>> calls to has_object_file_with_flags() to all of the refs.
>>
>> I fixed description by changing 'refs' to 'remote refs'. In my understanding,
>> git tries to check existence of remote refs even if we won't fetch such refs.
>
> During fetch, everything_local() tries to mark common part by
> walking the refs the other side advertised upon the first contact,
> so it is correct that the number of checks is not reduced in a fetch
> that does not fetch many refs, but the number of remote-tracking refs
> you have has no effect, so I doubt such a rephrasing would make the
> description more understandable.  "When fetching from a repository
> with large number of refs" is probably what you want to say, no?
>

For refs existing in local repository, everything_local looks to be able to find
corresponding object from packed or loose objects. And if it exists,
I think, cost of lstat(2) is relatively smaller than other operations.
But for remote refs, everything_local fails to find it from packed
object (this check is fast)
and it tries to find loose object by using lstat(2), and this fails and slow.
My patch is to skip this lstat(2) to non-existing ref objects for repositories
having large number of remote refs.

2018-03-10 4:41 GMT+09:00 Junio C Hamano <gitster@pobox.com>:
> Junio C Hamano <gitster@pobox.com> writes:
>
>>> Yes. But I think the default limit for the number of loose objects, 7000,
>>> gives us small overhead when we do enumeration of all objects.
>>
>> Hmph, I didn't see the code that does the estimation of loose object
>> count before starting to enumerate, though.
>
> Another thing the code could do to avoid negative consequences on
> projects that look quite different from yours (e.g. the other side
> does not have insane number of refs, but there are locally quite a
> few loose objects) is to count how many entries are on *refs list
> before we decide to enumerate all loose objects.  When the refs list
> is relatively shorter than the estimated number of loose objects
> (you can actually do the estimation based on sampling, or just rely
> on your assumed 7k), it may be a win _not_ to trigger the new code
> you are adding to this codepath with this patch.  I would imagine
> that the simplest implementaion may just count
>
>         for (ref = *refs, count = 0; ref && count++ < LIMIT; ref = ref->next)
>                 ;
>         use_oidset_optim = (LIMIT <= count);
>
> assuming your "up to 7k loose objects" and then experimenting to
> determine the LIMIT which is a rough number of refs that makes the
> oidset optimization worthwhile.
>
> We need a bit better/descriptive name for the LIMIT, if we go that
> route, though.
>

Sorry, 7000 was wrong. I wanted to say the default number of gc.auto, 6700.
I changed to count refs in for_each_loose_object(), and use it to
determine whether
we use oidset or not.

2018-03-10 4:54 GMT+09:00 Junio C Hamano <gitster@pobox.com>:
> Takuto Ikuta <tikuta@chromium.org> writes:
>
>> In repository having large number of remote refs, because to check
>
> Isn't this "When fetching from a repository with large number of
> refs,"?  The number of refs (whether it is local or remote-tracking)
> the local side has has nothing to do with the issue you are
> addressing, no?
>

Yes it has nothing to do with the issue. At least, my patch won't change
performance of git fetch for the repository having large number of local refs.

>> existence of each refs in local repository, 'git fetch' ends up doing a
>> lot of lstat(2) calls to see if it exists in loose form, which makes it
>> slow.
>
> Other than that, the above description reads much better and makes
> the result easier to understand.
>
>> This patch enumerates loose objects in hashmap beforehand and uses it to
>> check existence instead of using lstat(2) to improve performance of
>> fetch-pack for repositories having large number of remote refs compared
>> to the number of loose objects.
>
> We'd rather write this paragraph as if giving an order to the
> codebase "to be like so", e.g.
>
>         Instead of making as many lstat(2) calls as the refs the
>         remote side advertised to see if these objects exist in the
>         loose form, first enumerate all the existing loose objects
>         in hashmap beforehand and use it to check existence of
>         them...
>

Thanks, I changed description like it.

>> I took time stat of `git fetch` disabling quickfetch, so that fetch-pack
>
> I still do not know if a benchmark with quickfetch disabled gives
> relevant numbers, for reasons I gave earlier.  The relative numbers
> between Linux and MacBook look quite convincing, as they illustrate
> differences of lstat(2) performance on these platforms.
>
>>       for (ref = *refs; ref; ref = ref->next) {
>>               struct object *o;
>> +             unsigned int flags = OBJECT_INFO_QUICK;
>>
>> -             if (!has_object_file_with_flags(&ref->old_oid,
>> -                                             OBJECT_INFO_QUICK))
>> -                     continue;
>> +             if (!oidset_contains(&loose_oid_set, &ref->old_oid)) {
>> +                     /* I know this does not exist in the loose form,
>> +                      * so check if it exists in a non-loose form.
>> +                      */
>
>         /*
>          * Our multi-line comment looks like this,
>          * with opening slash-asterisk and closing
>          * asterisk-slash on their own lines.
>          */
>

I fixed.


Thanks, Takuto

  reply index

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-08 12:06 [PATCH] " Takuto Ikuta
2018-03-08 17:19 ` René Scharfe
2018-03-09 13:42   ` Takuto Ikuta
2018-03-08 18:42 ` Junio C Hamano
2018-03-09 13:11   ` [PATCH v2 0/1] " Takuto Ikuta
2018-03-09 13:11     ` [PATCH v2 1/1] " Takuto Ikuta
2018-03-09 13:26       ` [PATCH v3] " Takuto Ikuta
2018-03-09 19:54         ` Junio C Hamano
2018-03-10 13:19           ` Takuto Ikuta [this message]
2018-03-13 17:53             ` Junio C Hamano
2018-03-14  6:26               ` Takuto Ikuta
2018-03-10 12:34         ` [PATCH v4] " Takuto Ikuta
2018-03-10 12:46           ` [PATCH v5] " Takuto Ikuta
2018-03-13 19:04             ` Junio C Hamano
2018-03-14  6:05           ` [PATCH v6] " Takuto Ikuta
2018-03-14  6:32             ` [PATCH v7] " Takuto Ikuta
2018-03-09 14:12   ` [PATCH] " Takuto Ikuta
2018-03-09 18:00     ` Junio C Hamano
2018-03-09 19:41       ` Junio C Hamano
2018-03-13 15:30   ` [PATCH] sha1_file: restore OBJECT_INFO_QUICK functionality Jonathan Tan

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALNjmMqBbZTFVRnc__wewWy3808n9J9xfgu8ZH-FWyWJKvqb9w@mail.gmail.com \
    --to=tikuta@chromium.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox