Skip to content

Commit d2a6845

Browse files
committed
Merge pull request #1 from orivej/parallel-update
Parallel fetching
2 parents 9902f78 + 3b77c57 commit d2a6845

File tree

5 files changed

+73
-26
lines changed

5 files changed

+73
-26
lines changed

misc.lisp

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,31 +162,41 @@
162162
(intern (string-upcase project))))
163163

164164

165-
(defun call-with-skipping (fun &key (stream *standard-output*))
166-
(handler-bind ((error (lambda (condition)
167-
(when (find-restart 'skip)
168-
(when (boundp '*current-mapped-source*)
169-
(format stream "~&* ~A~%" *current-mapped-source*)
170-
(format stream ":: from ~A~%"
171-
(find-source *current-mapped-source*)))
172-
(format stream "~&SKIPPING (~A)~%" condition)
173-
(invoke-restart 'skip)))))
174-
(funcall fun)))
175-
176-
(defun update-what-you-can (&optional file)
165+
(defvar *output-lock* (bt:make-lock "output-lock"))
166+
167+
(defun call-with-skipping (fun &key (stream *standard-output*) parallel)
168+
(flet ((invoke-skip (condition)
169+
(when (find-restart 'skip)
170+
(bt:with-lock-held (*output-lock*)
171+
(when (boundp '*current-mapped-source*)
172+
(format stream "~&* ~A~%" *current-mapped-source*)
173+
(format stream ":: from ~A~%"
174+
(find-source *current-mapped-source*)))
175+
(format stream "~&SKIPPING (~A)~%" condition))
176+
(invoke-restart 'skip))))
177+
(if (not parallel)
178+
(handler-bind ((error #'invoke-skip))
179+
(funcall fun))
180+
(lparallel:task-handler-bind ((error #'invoke-skip))
181+
(funcall fun)))))
182+
183+
(defun update-what-you-can (&optional file parallel)
177184
(flet ((action (stream)
178185
(call-with-skipping
179186
(lambda ()
180-
(map-sources (lambda (source)
181-
(force-output stream)
182-
(format t "~&Updating ~S from ~A~%"
183-
(project-name source)
184-
(location source))
185-
(update-source-cache source))))
186-
:stream stream)))
187+
(funcall (if parallel 'pmap-sources 'map-sources)
188+
(lambda (source)
189+
(bt:with-lock-held (*output-lock*)
190+
(force-output stream)
191+
(format t "~&Updating ~S from ~A~%"
192+
(project-name source)
193+
(location source)))
194+
(update-source-cache source))))
195+
:stream stream
196+
:parallel parallel)))
187197
(if file
188198
(with-open-file (stream file :direction :output
189-
:if-exists :rename-and-delete)
199+
:if-exists :rename-and-delete)
190200
(action (make-broadcast-stream *standard-output* stream)))
191201
(action *standard-output*))))
192202

quicklisp-controller.asd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#:cl-ppcre
1111
#:alexandria
1212
#:drakma
13-
#:ironclad)
13+
#:ironclad
14+
#:lparallel)
1415
:serial t
1516
:components ((:file "tarhash")
1617
(:file "package")

upstream-bzr.lisp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99
:checkout-subcommand "branch"
1010
:update-subcommand "merge"))
1111

12+
(defmethod source-host :around ((source bzr-source))
13+
(if (string= "lp:" (location source) :end2 3)
14+
"launchpad.net"
15+
(call-next-method)))
16+
1217
(defmethod make-release-tarball ((source bzr-source) output-file)
1318
(let* ((prefix (release-tarball-prefix source))
1419
(tar-name (string-right-trim "/" prefix))
15-
(checkout (ensure-source-cache source)))
20+
(checkout (ensure-source-cache source)))
1621
(in-temporary-directory prefix
1722
(let ((tempgz (make-pathname :name tar-name :type "tgz")))
1823
(with-posix-cwd checkout

upstream-cvs.lisp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
(defmethod source-location-initargs ((source cvs-oddmodule-source))
1919
(list :location :module-name))
2020

21+
(defmethod source-host ((source cvs-source))
22+
(let* ((location (location source))
23+
(host-start (1+ (position #\@ location)))
24+
(host-end (position #\: location :start host-start)))
25+
(subseq location host-start host-end)))
26+
2127
(defmethod source-description ((source cvs-source))
2228
(format nil "cvs -d ~A co ~A"
2329
(location source)

upstream.lisp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
(:method (source)
8484
(list :location)))
8585

86+
(defgeneric source-host (source)
87+
(:method (source)
88+
(puri:uri-host (puri:parse-uri (location source)))))
89+
8690
(defgeneric parse-location (source location-string)
8791
(:documentation "Update an instance by parsing its location value.")
8892
(:method (source location-string)
@@ -117,14 +121,35 @@
117121

118122
(defvar *current-mapped-source* nil)
119123

124+
(defun map-source (fun source)
125+
(let ((*current-mapped-source* (project-name source)))
126+
(with-simple-restart (skip "Skip ~A source" *current-mapped-source*)
127+
(funcall fun source))))
128+
120129
(defun map-sources (fun)
121130
(with-simple-restart (abort "Give up entirely")
122131
(dolist (source-file
123132
(directory #p"quicklisp-controller:projects;**;source.txt"))
124-
(let* ((project-name (pathname-project-name source-file))
125-
(*current-mapped-source* project-name))
126-
(with-simple-restart (skip "Skip ~A source" project-name)
127-
(funcall fun (load-source-file project-name source-file)))))))
133+
(let ((project-name (pathname-project-name source-file)))
134+
(map-source fun (load-source-file project-name source-file))))))
135+
136+
(defun pmap-sources (fun)
137+
(let ((dependency-tree (lparallel:make-ptree))
138+
(host-dependency (make-hash-table :test 'equal))
139+
(i 0))
140+
(map-sources (lambda (source)
141+
(let ((host (source-host source)))
142+
(lparallel:ptree-fn i (gethash host host-dependency)
143+
(lambda (&optional arg)
144+
(declare (ignore arg))
145+
(map-source fun source))
146+
dependency-tree)
147+
(setf (gethash host host-dependency) (list i))
148+
(incf i))))
149+
(lparallel:ptree-fn 'everything (loop for j below i collect j)
150+
(constantly nil) dependency-tree)
151+
(lparallel:call-ptree 'everything dependency-tree)
152+
nil))
128153

129154
(defun find-source (name)
130155
(block nil

0 commit comments

Comments
 (0)