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

use Tar.jl to create and extract tarballs #29

Merged
merged 3 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[BinaryProvider]]
deps = ["Libdl", "SHA"]
git-tree-sha1 = "5b08ed6036d9d3f0ee6369410b830f8873d4024c"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.5.8"

Copy link
Member

Choose a reason for hiding this comment

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

:)

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -19,9 +13,9 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[HTTP]]
deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"]
git-tree-sha1 = "5c49dab19938b119fe204fd7d7e8e174f4e9c68b"
git-tree-sha1 = "fe31f4ff144392ad8176f5c7c03cca6ba320271c"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "0.8.8"
version = "0.8.14"

[[IniFile]]
deps = ["Test"]
Expand All @@ -34,6 +28,7 @@ deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[LibGit2]]
deps = ["Printf"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[Libdl]]
Expand All @@ -47,10 +42,16 @@ deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[MbedTLS]]
deps = ["BinaryProvider", "Dates", "Libdl", "Random", "Sockets"]
git-tree-sha1 = "85f5947b53c8cfd53ccfa3f4abae31faa22c2181"
deps = ["Dates", "MbedTLS_jll", "Random", "Sockets"]
git-tree-sha1 = "426a6978b03a97ceb7ead77775a1da066343ec6e"
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
version = "0.7.0"
version = "1.0.2"

[[MbedTLS_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "c83f5a1d038f034ad0549f9ee4d5fac3fb429e33"
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
version = "2.16.0+2"

[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
Expand All @@ -77,6 +78,11 @@ uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[Tar]]
git-tree-sha1 = "eaee2dba5f1f91c17e8a80d13303b1f236fea2f3"
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
version = "1.3.0"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"

[compat]
HTTP = "0.8"
Expand Down
41 changes: 7 additions & 34 deletions bin/gen_static.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,11 @@ import Pkg
import Pkg.TOML
import Pkg.Artifacts: download_artifact, artifact_path
import LibGit2

# TODO: ensure all registries are git clones
Pkg.update()
import Tar

mkpath(clones_dir)
mkpath(static_dir)

const tar_opts = ```
--format=posix
--numeric-owner
--owner=0
--group=0
--mode=go-w,+X
--mtime=1970-01-01
--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime,delete=mtime
--no-recursion
```
# reproducible tarball options based on
# http://h2.jaguarpaw.co.uk/posts/reproducible-tar/

const compress = `gzip -9`
const decompress = `gzcat`

Expand All @@ -43,25 +28,11 @@ function make_tarball(
tarball::AbstractString,
tree_path::AbstractString,
)
paths = String[]
for (root, dirs, files) in walkdir(tree_path)
path = root != tree_path ? relpath(root, tree_path) : ""
for file in [dirs; files]
push!(paths, joinpath(path, file))
open(tarball, write=true) do io
open(pipeline(compress, io), write=true) do io
Tar.create(tree_path, io)
Copy link
Contributor

@johnnychen94 johnnychen94 Apr 29, 2020

Choose a reason for hiding this comment

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

I've observed a performance regression forking this PR and #32 by building tarballs for General registry and [email protected]+5, which have 15 tarballs(1 registry, 1 package source codes and 13 artifacts) to build.

  • before: 24.134260 seconds (7.35 M allocations: 472.674 MiB, 1.60% gc time)
  • after: 32.119186 seconds (5.74 M allocations: 438.242 MiB, 0.39% gc time)

Juno.@profiler tells me that Tar.create is the bottleneck.

The overall changes can be found at johnnychen94/StorageMirrorServer.jl@f77fb30


bash-3.2$ gtar --version
tar (GNU tar) 1.30
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.
julia> versioninfo()
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 8

(StorageServer) pkg> st Tar
Project StorageServer v0.1.0
Status `~/Documents/Julia/StorageServer/Project.toml`
  [a4e569a6] Tar v1.3.0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Being 33% slower than the hyper-optimized GNU tar is quite good. I've created an issue about using sendfile to optimize tarball creation and extraction: JuliaIO/Tar.jl#33. However, matching performance of GNU tar isn't really a high priority. It's also possible since we're not sending data directly to a real file descriptor but to a TranscodingStream that the sendfile optimization wouldn't actually help in this case, but it's also possible that we should be using a buffer size that matches what TranscodingStreams uses and maybe avoid multiple buffers. In general, what's needed is an API for saying "send this much data from here to here" that just does whatever is most efficient for the given source and destination.

end
end
sort!(paths)
mktemp() do paths_file, io
for path in paths
print(io, "$path\0")
end
close(io)
open(tarball, write=true) do io
tar_cmd = `gtar $tar_opts -cf - -C $tree_path --null -T $paths_file`
run(pipeline(tar_cmd, compress, io))
end
end
return
end

function create_git_tarball(
Expand Down Expand Up @@ -94,7 +65,9 @@ function verify_tarball_hash(
)
local hash
mktempdir() do tmp_dir
run(pipeline(`$decompress $tarball`, `tar -C $tmp_dir -x`))
open(pipeline(tarball, decompress)) do io
Tar.extract(io, tmp_dir)
end
hash = bytes2hex(Pkg.GitTools.tree_hash(tmp_dir))
chmod(tmp_dir, 0o777, recursive=true)
end
Expand Down