{"thread":{"id":"51539","subject":"Settings for minimizing repacking (and keeping 'rsync' happy)","startedAt":"2019-07-27T23:41:47Z","lastAt":"2019-07-29T20:16:14Z","messageCount":5,"participants":["ardi","Jeff King","Ævar Arnfjörð Bjarmason","Konstantin Ryabitsev"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"379434","messageId":"CA+fZqCXBjA5jsYg7L7X1VhJZXrp9NP+dR1SQWK9fAf9b1jgpCg@mail.gmail.com","threadId":"51539","inReplyTo":null,"subject":"Settings for minimizing repacking (and keeping 'rsync' happy)","fromName":"ardi","fromEmail":"ardillasdelmonte@gmail.com","sentAt":"2019-07-27T23:41:34Z","receivedAt":"2019-07-27T23:41:47Z","isPatch":false,"sender":{"key":"ardillasdelmonte@gmail.com","avatar":null},"body":"Hi!\n\nSome of my Git repositories have mirrors, maintained with 'rsync'. I\nwant to have some level of repacking, so that the repositories are\nefficient, but I also want it to minimize it, so that 'rsync' never\nhas to perform a big transfer for the repositories.\n\nFor example, I think it would be fine if files are repacked just once\nin their lifetimes, and then that resulting pack file is never\nrepacked again. I did read the gc.bigPackThreshold and\ngc.autoPackLimit settings, but I don't think they would accomplish\nthat.\n\nBasically, what I'm describing is the behaviour of not packing files\nuntil the resulting pack would be a given size (say 10MB for example),\nand then never repack such ~10MB packs again, ever.\n\nCan this be done with some Git settings? And do you foresee any kind\nof serious drawback or potential problem with this kind of behaviour?\n\nThanks!!\n\nardi\n"},{"id":"379486","messageId":"20190729094229.GA2415@sigill.intra.peff.net","threadId":"51539","inReplyTo":"CA+fZqCXBjA5jsYg7L7X1VhJZXrp9NP+dR1SQWK9fAf9b1jgpCg@mail.gmail.com","subject":"Re: Settings for minimizing repacking (and keeping 'rsync' happy)","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-07-29T09:42:29Z","receivedAt":"2019-07-29T09:42:31Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jul 28, 2019 at 01:41:34AM +0200, ardi wrote:\n\n> Some of my Git repositories have mirrors, maintained with 'rsync'. I\n> want to have some level of repacking, so that the repositories are\n> efficient, but I also want it to minimize it, so that 'rsync' never\n> has to perform a big transfer for the repositories.\n\nYes, this is a common problem. The solutions I've seen/used are:\n\n  - use a git-aware transport like git-fetch that can negotiate which\n    objects to send\n\n  - use a tool that can find duplicated chunks across files. Many\n    de-duping backup systems (e.g., borg) use a rolling hash similar to\n    rsync to find moveable chunks, but then look up those chunks in a\n    master index (whereas rsync is always looking to match chunks in a\n    file of the same name). This works well in practice because Git is\n    not usually rewriting most of the data, but just shuffling it around\n    between files.\n\n    In theory it shouldn't be that hard to tell the receiving rsync to\n    look for source chunks not just in the file of the same name, but\n    from a set of existing packfiles (say, everything already in\n    .git/objects/pack/ on the receiver). But I don't know offhand of an\n    option to rsync to do so.\n\n> For example, I think it would be fine if files are repacked just once\n> in their lifetimes, and then that resulting pack file is never\n> repacked again. I did read the gc.bigPackThreshold and\n> gc.autoPackLimit settings, but I don't think they would accomplish\n> that.\n> \n> Basically, what I'm describing is the behaviour of not packing files\n> until the resulting pack would be a given size (say 10MB for example),\n> and then never repack such ~10MB packs again, ever.\n> \n> Can this be done with some Git settings? And do you foresee any kind\n> of serious drawback or potential problem with this kind of behaviour?\n\nYou can mark a pack to be kept forever by creating a matching\n\"pack-1234abcd.keep\" file. That doesn't do your automatic \"I want 10MB\npacks\" thing, but if you did it occasionally at the right frequency,\nyou'd end up with a bunch of 10MB-ish packs.\n\nBut there are downsides to having a bunch of packs:\n\n  - object lookups are O(log n) within a single pack, but O(n) over the\n    number of packs. So if you get a very large number of packs, normal\n    operations will start to suffer. This is mitigated by the new \"midx\"\n    feature, which generates an index for multiple packs.\n\n  - git doesn't allow delta compression across packs. So imagine you\n    have ten versions of a file that's 5kb, and each version changes\n    about 100 bytes. In a single pack, we'd store one base object, plus\n    9 deltas, for a total of about 6kb (5000 + 9*100). Across two packs,\n    we'd store ~11kb (2*5000 + 8*100). And the worst case is ten packs\n    at 50kb.\n\n    As a more real-world example, try this:\n\n      git -c pack.packsizelimit=10M repack -ad\n\n    In a fresh clone of git.git, the size of the pack directory jumps\n    from 88MB to 168MB. And in a time-based split (i.e., creating a new\n    10MB pack every week), it may be even worse. The command above\n    ordered the objects optimally to keep deltas together and _then_\n    split things. Whereas a time-based scheme would likely sprinkle\n    versions of a file across more packs.\n\n    It should be possible to loosen this restriction and allow\n    cross-pack deltas, but it would be very risky. The assumption that\n    packs are independent of each other is implicit in much of Git's\n    repacking code, so it would be easy to introduce a bug where we\n    generate a circular dependency (object A in pack X is a delta\n    against object B in pack Y, which is a delta against object A --\n    oops, we don't have a full copy anymore).\n\n-Peff\n"},{"id":"379496","messageId":"87tvb55799.fsf@evledraar.gmail.com","threadId":"51539","inReplyTo":"20190729094229.GA2415@sigill.intra.peff.net","subject":"Re: Settings for minimizing repacking (and keeping 'rsync' happy)","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2019-07-29T12:56:34Z","receivedAt":"2019-07-29T12:56:39Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Jul 29 2019, Jeff King wrote:\n\n> On Sun, Jul 28, 2019 at 01:41:34AM +0200, ardi wrote:\n>\n>> Some of my Git repositories have mirrors, maintained with 'rsync'. I\n>> want to have some level of repacking, so that the repositories are\n>> efficient, but I also want it to minimize it, so that 'rsync' never\n>> has to perform a big transfer for the repositories.\n>\n> Yes, this is a common problem. The solutions I've seen/used are:\n>\n>   - use a git-aware transport like git-fetch that can negotiate which\n>     objects to send\n>\n>   - use a tool that can find duplicated chunks across files. Many\n>     de-duping backup systems (e.g., borg) use a rolling hash similar to\n>     rsync to find moveable chunks, but then look up those chunks in a\n>     master index (whereas rsync is always looking to match chunks in a\n>     file of the same name). This works well in practice because Git is\n>     not usually rewriting most of the data, but just shuffling it around\n>     between files.\n>\n>     In theory it shouldn't be that hard to tell the receiving rsync to\n>     look for source chunks not just in the file of the same name, but\n>     from a set of existing packfiles (say, everything already in\n>     .git/objects/pack/ on the receiver). But I don't know offhand of an\n>     option to rsync to do so.\n>\n>> For example, I think it would be fine if files are repacked just once\n>> in their lifetimes, and then that resulting pack file is never\n>> repacked again. I did read the gc.bigPackThreshold and\n>> gc.autoPackLimit settings, but I don't think they would accomplish\n>> that.\n>>\n>> Basically, what I'm describing is the behaviour of not packing files\n>> until the resulting pack would be a given size (say 10MB for example),\n>> and then never repack such ~10MB packs again, ever.\n>>\n>> Can this be done with some Git settings? And do you foresee any kind\n>> of serious drawback or potential problem with this kind of behaviour?\n>\n> You can mark a pack to be kept forever by creating a matching\n> \"pack-1234abcd.keep\" file. That doesn't do your automatic \"I want 10MB\n> packs\" thing, but if you did it occasionally at the right frequency,\n> you'd end up with a bunch of 10MB-ish packs.\n>\n> But there are downsides to having a bunch of packs:\n>\n>   - object lookups are O(log n) within a single pack, but O(n) over the\n>     number of packs. So if you get a very large number of packs, normal\n>     operations will start to suffer. This is mitigated by the new \"midx\"\n>     feature, which generates an index for multiple packs.\n>\n>   - git doesn't allow delta compression across packs. So imagine you\n>     have ten versions of a file that's 5kb, and each version changes\n>     about 100 bytes. In a single pack, we'd store one base object, plus\n>     9 deltas, for a total of about 6kb (5000 + 9*100). Across two packs,\n>     we'd store ~11kb (2*5000 + 8*100). And the worst case is ten packs\n>     at 50kb.\n>\n>     As a more real-world example, try this:\n>\n>       git -c pack.packsizelimit=10M repack -ad\n>\n>     In a fresh clone of git.git, the size of the pack directory jumps\n>     from 88MB to 168MB. And in a time-based split (i.e., creating a new\n>     10MB pack every week), it may be even worse. The command above\n>     ordered the objects optimally to keep deltas together and _then_\n>     split things. Whereas a time-based scheme would likely sprinkle\n>     versions of a file across more packs.\n>\n>     It should be possible to loosen this restriction and allow\n>     cross-pack deltas, but it would be very risky. The assumption that\n>     packs are independent of each other is implicit in much of Git's\n>     repacking code, so it would be easy to introduce a bug where we\n>     generate a circular dependency (object A in pack X is a delta\n>     against object B in pack Y, which is a delta against object A --\n>     oops, we don't have a full copy anymore).\n\nThe thread I started at\nhttps://public-inbox.org/git/87bmhiykvw.fsf@evledraar.gmail.com/ should\nalso be of interest. I.e. we could have some knobs to create more\n\"stable\" packs, I know rsync does some in-file hashing, but I don't\nif/how that works if you have 1 file split into N where some chunks in\nthe N are in the one file.\n\nBut it's possible to imagine a repacking algorithm that would keep\nproducing entirely new packs but arrange for it to be ordered/delta'd in\nsuch a way that it optimizes for page-by-page similarity to an older\npack to some degree.\n\nSo e.g. in the examples you mention break the delta chain at 5, then\npick it up again once it's 10 etc. So the intermediate packs where it's\n6, 7, 8, 9 would have the new stuff at the end.\n"},{"id":"379503","messageId":"CAMwyc-TuzSd8UdmL95DhCAZ=bRFxjF6jq_10R33jn458Wv_=9g@mail.gmail.com","threadId":"51539","inReplyTo":"CA+fZqCXBjA5jsYg7L7X1VhJZXrp9NP+dR1SQWK9fAf9b1jgpCg@mail.gmail.com","subject":"Re: Settings for minimizing repacking (and keeping 'rsync' happy)","fromName":"Konstantin Ryabitsev","fromEmail":"konstantin@linuxfoundation.org","sentAt":"2019-07-29T14:35:28Z","receivedAt":"2019-07-29T14:35:42Z","isPatch":false,"sender":{"key":"konstantin@linuxfoundation.org","avatar":"https://gravatar.com/avatar/7cb8827c6de56e1bd2dea16508c6708aa43feed3bf3813bcdacecdf96ceadd79?d=mp&s=160"},"body":"On Sat, 27 Jul 2019 at 19:41, ardi <ardillasdelmonte@gmail.com> wrote:\n>\n> Hi!\n>\n> Some of my Git repositories have mirrors, maintained with 'rsync'. I\n> want to have some level of repacking, so that the repositories are\n> efficient, but I also want it to minimize it, so that 'rsync' never\n> has to perform a big transfer for the repositories.\n\nWe use grokmirror to replicate several thousand repositories worldwide\nusing git-native protocols. It is fast and very efficient.\nhttps://github.com/mricon/grokmirror\n\nRegards,\n-- \nKonstantin Ryabitsev\nDirector, Projects IT\nThe Linux Foundation\nMontréal, Québec\n"},{"id":"379547","messageId":"20190729201610.GG14943@sigill.intra.peff.net","threadId":"51539","inReplyTo":"87tvb55799.fsf@evledraar.gmail.com","subject":"Re: Settings for minimizing repacking (and keeping 'rsync' happy)","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-07-29T20:16:10Z","receivedAt":"2019-07-29T20:16:14Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jul 29, 2019 at 02:56:34PM +0200, Ævar Arnfjörð Bjarmason wrote:\n\n> The thread I started at\n> https://public-inbox.org/git/87bmhiykvw.fsf@evledraar.gmail.com/ should\n> also be of interest. I.e. we could have some knobs to create more\n> \"stable\" packs, I know rsync does some in-file hashing, but I don't\n> if/how that works if you have 1 file split into N where some chunks in\n> the N are in the one file.\n> \n> But it's possible to imagine a repacking algorithm that would keep\n> producing entirely new packs but arrange for it to be ordered/delta'd in\n> such a way that it optimizes for page-by-page similarity to an older\n> pack to some degree.\n\nI actually think that's the part that rsync does well. We don't keep\npage-by-page similarity, but rsync (and other tools like borg) are\nreally good at finding the moved chunks. The problem is just that it\ndoesn't know to compare chunks between two files with unrelated names.\n\n-Peff\n"}]}