Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1216)

Side by Side Diff: third_party/gsutil/gslib/addlhelp/prod.py

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2012 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from gslib.help_provider import HELP_NAME
16 from gslib.help_provider import HELP_NAME_ALIASES
17 from gslib.help_provider import HELP_ONE_LINE_SUMMARY
18 from gslib.help_provider import HelpProvider
19 from gslib.help_provider import HELP_TEXT
20 from gslib.help_provider import HelpType
21 from gslib.help_provider import HELP_TYPE
22
23 _detailed_help_text = ("""
24 <B>OVERVIEW</B>
25 If you use gsutil in large production tasks (such as uploading or
26 downloading many GB of data each night), there are a number of things
27 you can do to help ensure success. Specifically, this section discusses
28 how to script large production tasks around gsutil's resumable transfer
29 mechanism.
30
31
32 <B>BACKGROUND ON RESUMABLE TRANSFERS</B>
33 First, it's helpful to understand gsutil's resumable transfer mechanism,
34 and how your script needs to be implemented around this mechanism to work
35 reliably. gsutil uses the resumable transfer support in the boto library
36 when you attempt to upload or download a file larger than a configurable
37 threshold (by default, this threshold is 1MB). When a transfer fails
38 partway through (e.g., because of an intermittent network problem),
39 boto uses a randomized binary exponential backoff-and-retry strategy:
40 wait a random period between [0..1] seconds and retry; if that fails,
41 wait a random period between [0..2] seconds and retry; and if that
42 fails, wait a random period between [0..4] seconds, and so on, up to a
43 configurable number of times (the default is 6 times). Thus, the retry
44 actually spans a randomized period up to 1+2+4+8+16+32=63 seconds.
45
46 If the transfer fails each of these attempts with no intervening
47 progress, gsutil gives up on the transfer, but keeps a "tracker" file
48 for it in a configurable location (the default location is ~/.gsutil/,
49 in a file named by a combination of the SHA1 hash of the name of
50 the bucket and object being transferred, the epoch time of the
51 transfer, and the last 16 characters of the file name). When
52 transfers fail in this fashion, you can rerun gsutil at some later
53 time (e.g., after the networking problem has been resolved), and
54 the resumable transfer picks up where it left off.
55
56
57 <B>SCRIPTING DATA TRANSFER TASKS</B>
58 To script large production data transfer tasks around this mechanism,
59 you can implement a script that runs periodically, determines which file
60 transfers have not yet succeeded, and runs gsutil to copy them. Below,
61 we offer a number of suggestions about how this type of scripting should
62 be implemented:
63
64 1. When resumable transfers fail without any progress 6 times in a row
65 over the course of up to 63 seconds, it probably won't work to simply
66 retry the transfer immediately. A more successful strategy would be to
67 have a cron job that runs every 30 minutes, determines which transfers
68 need to be run, and runs them. If the network experiences intermittent
69 problems, the script picks up where it left off and will eventually
70 succeed (once the network problem has been resolved).
71
72 2. If your business depends on timely data transfer, you should consider
73 implementing some network monitoring. For example, you can implement
74 a task that attempts a small download every few minutes and raises an
75 alert if the attempt fails for several attempts in a row (or more or less
76 frequently depending on your requirements), so that your IT staff can
77 investigate problems promptly. As usual with monitoring implementations,
78 you should experiment with the alerting thresholds, to avoid false
79 positive alerts that cause your staff to begin ignoring the alerts.
80
81 3. There are a variety of ways you can determine what files remain to be
82 transferred. We recommend that you avoid attempting to get a complete
83 listing of a bucket containing many objects (e.g., tens of thousands
84 or more). One strategy is to structure your object names in a way that
85 represents your transfer process, and use gsutil prefix wildcards to
86 request partial bucket listings. For example, if your periodic process
87 involves downloading the current day's objects, you could name objects
88 using a year-month-day-object-ID format and then find today's objects by
89 using a command like gsutil ls gs://bucket/2011-09-27-*. Note that it
90 is more efficient to have a non-wildcard prefix like this than to use
91 something like gsutil ls gs://bucket/*-2011-09-27. The latter command
92 actually requests a complete bucket listing and then filters in gsutil,
93 while the former asks Google Storage to return the subset of objects
94 whose names start with everything up to the *.
95
96 For data uploads, another technique would be to move local files from a "to
97 be processed" area to a "done" area as your script successfully copies files
98 to the cloud. You can do this in parallel batches by using a command like:
99
100 gsutil -m cp -R to_upload/subdir_$i gs://bucket/subdir_$i
101
102 where i is a shell loop variable. Make sure to check the shell $status
103 variable is 0 after each gsutil cp command, to detect if some of the copies
104 failed, and rerun the affected copies.
105
106 With this strategy, the file system keeps track of all remaining work to
107 be done.
108
109 4. If you have really large numbers of objects in a single bucket
110 (say hundreds of thousands or more), you should consider tracking your
111 objects in a database instead of using bucket listings to enumerate
112 the objects. For example this database could track the state of your
113 downloads, so you can determine what objects need to be downloaded by
114 your periodic download script by querying the database locally instead
115 of performing a bucket listing.
116
117 5. Make sure you don't delete partially downloaded files after a transfer
118 fails: gsutil picks up where it left off (and performs an MD5 check of
119 the final downloaded content to ensure data integrity), so deleting
120 partially transferred files will cause you to lose progress and make
121 more wasteful use of your network. You should also make sure whatever
122 process is waiting to consume the downloaded data doesn't get pointed
123 at the partially downloaded files. One way to do this is to download
124 into a staging directory and then move successfully downloaded files to
125 a directory where consumer processes will read them.
126
127 6. If you have a fast network connection, you can speed up the transfer of
128 large numbers of files by using the gsutil -m (multi-threading /
129 multi-processing) option. Be aware, however, that gsutil doesn't attempt to
130 keep track of which files were downloaded successfully in cases where some
131 files failed to download. For example, if you use multi-threaded transfers
132 to download 100 files and 3 failed to download, it is up to your scripting
133 process to determine which transfers didn't succeed, and retry them. A
134 periodic check-and-run approach like outlined earlier would handle this case.
135
136 If you use parallel transfers (gsutil -m) you might want to experiment with
137 the number of threads being used (via the parallel_thread_count setting
138 in the .boto config file). By default, gsutil uses 24 threads. Depending
139 on your network speed, available memory, CPU load, and other conditions,
140 this may or may not be optimal. Try experimenting with higher or lower
141 numbers of threads, to find the best number of threads for your environment.
142 """)
143
144
145 class CommandOptions(HelpProvider):
146 """Additional help about using gsutil for production tasks."""
147
148 help_spec = {
149 # Name of command or auxiliary help info for which this help applies.
150 HELP_NAME : 'prod',
151 # List of help name aliases.
152 HELP_NAME_ALIASES : ['production', 'resumable', 'resumable upload',
153 'resumable transfer', 'resumable download',
154 'scripts', 'scripting'],
155 # Type of help:
156 HELP_TYPE : HelpType.ADDITIONAL_HELP,
157 # One line summary of this help.
158 HELP_ONE_LINE_SUMMARY : 'Scripting production data transfers with gsutil',
159 # The full help text.
160 HELP_TEXT : _detailed_help_text,
161 }
OLDNEW
« no previous file with comments | « third_party/gsutil/gslib/addlhelp/naming.py ('k') | third_party/gsutil/gslib/addlhelp/projects.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698