Megatest

Check-in [93c1073c06]
Login
Overview
Comment:Made wait-for-qif remove all old queries
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | v1.80-close-idle-connections
Files: files | file ages | folders
SHA1: 93c1073c0623cf27a00c90f27cbcc00e9b599400
User & Date: mmgraham on 2023-02-09 11:02:52
Other Links: branch diff | manifest | tags
Context
2023-02-09
11:02
Made wait-for-qif remove all old queries Leaf check-in: 93c1073c06 user: mmgraham tags: v1.80-close-idle-connections
2023-02-07
16:24
fix for assert check-in: a7577f7a9b user: pjhatwal tags: v1.80-close-idle-connections
Changes

Modified dbfile.scm from [bba1a9d47e] to [5291d8f563].

1032
1033
1034
1035
1036
1037
1038
1039

1040
1041
1042

1043
1044
1045

1046
1047
1048
1049
1050
1051
1052
1053


1054
1055
1056
1057
1058


1059


1060
1061
1062
1063
1064
1065
1066
1067
1068
1069





1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080

1081
1082
1083
1084
1085
1086
1087



1088
1089
1090
1091
1092
1093
1094
(define dbfile:db-init-proc (make-parameter #f))

(define keep-age-param (make-parameter 10))
(define qif-slope      (make-parameter 100))

;; create a dropping near the db file in a qif dir
;; use count of such files to gate queries (queries in flight)
;;

(define (dbfile:wait-for-qif fname run-id params)
  (let* ((thedir  (pathname-directory fname))
	 (destdir (conc thedir"/qif-"run-id))

	 (uniqn   (get-area-path-signature (conc (or run-id "main") params)))
	 (crumbn  (conc destdir"/"(current-seconds)"-"uniqn"."(current-process-id))))
    (if (not (file-exists? destdir))(create-directory (conc destdir"/attic") #t))

    (let loop ((count 0))
      (let* ((currlks (glob (conc destdir"/*")))
	     (numqrys (length currlks))
	     (delayval (cond ;; do a droopish curve
			((> numqrys 50)
			 (if (> numqrys 50)
			     (for-each
			      (lambda (f)


				(if (> (- (current-seconds)
					  (handle-exceptions
					      exn
					    (current-seconds) ;; file is likely gone, just fake out
					    (file-modification-time f)))


				       (keep-age-param))


				    (let* ((basedir (pathname-directory f))
					   (filen   (pathname-file f))
					   (destf   (conc basedir"/attic/"filen)))
				      (dbfile:print-err "Moving qif file "f" older than 10 seconds to "destf)
				      ;; (delete-file* f)
				      (handle-exceptions
					  exn
					#t
					(file-move f destf #t)))))
			      currlks))





			 1) ;; 50 and above => 1
			((> numqrys 10) (* numqrys (/ 1 (qif-slope)))) ;; slope of 1/100
			;; ((> numqrys 30) 0.50)
			;; ((> numqrys 25) 0.20)
			;; ((> numqrys 20) 0.10)
			;; ((> numqrys 15) 0.05)
			;; ((> numqrys 10) 0.01)
			(else #f))))
	(if (and delayval
		 (< count 5))
	    (begin

	      (thread-sleep! delayval)
	      (loop (+ count 1))))))
    (with-output-to-file crumbn
      (lambda ()
	(print fname" run-id="run-id" params="params)
	))
    crumbn))




(define no-condition-db-with-db (make-parameter #t))

;; (db:with-db dbstruct run-id sqlite3:exec "select blah fgrom blaz;")
;; r/w is a flag to indicate if the db is modified by this query #t = yes, #f = no
;;
(define (db:with-db dbstruct run-id r/w proc . params)







|
>



>



>



<
|
|
|
|
>
>
|
|
|
|
|
>
>
|
>
>
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
|

<
<
<
<
<




>







>
>
>







1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051

1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084





1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
(define dbfile:db-init-proc (make-parameter #f))

(define keep-age-param (make-parameter 10))
(define qif-slope      (make-parameter 100))

;; create a dropping near the db file in a qif dir
;; use count of such files to gate queries (queries in flight)


(define (dbfile:wait-for-qif fname run-id params)
  (let* ((thedir  (pathname-directory fname))
	 (destdir (conc thedir"/qif-"run-id))
         ;; (destdir (conc thedir"/qif"))
	 (uniqn   (get-area-path-signature (conc (or run-id "main") params)))
	 (crumbn  (conc destdir"/"(current-seconds)"-"uniqn"."(current-process-id))))
    (if (not (file-exists? destdir))(create-directory (conc destdir"/attic") #t))

    (let loop ((count 0))
      (let* ((currlks (glob (conc destdir"/*")))
	     (numqrys (length currlks))

             (cleanup 
                (if (> numqrys 0)
	          (for-each
		    (lambda (f)
		      (if
                       (and (not (directory? f))
                        (> (- (current-seconds)
			    (handle-exceptions
			       exn
			      (current-seconds) ;; file is likely gone, just fake out
			      (file-modification-time f)
                            )
                          )
		          (keep-age-param)
                        )
                       )
		      (let* ((basedir (pathname-directory f))
			   (filen   (pathname-file f))
			   (destf   (conc basedir"/attic/"filen)))
		      ;; (dbfile:print-err "Moving qif file "f" older than " (keep-age-param) " seconds to "destf)
		      ;; (delete-file* f)
		      (handle-exceptions
			  exn
			#t
			(file-move f destf #t)))))
	             currlks
                   )
                 )
             )
	     (delayval (cond ;; do a droopish curve
			((> numqrys 50)
			   1) ;; 50 and above => 1
			((> numqrys 10) (* numqrys (/ 1 (qif-slope)))) ;; slope of 1/100





			(else #f))))
	(if (and delayval
		 (< count 5))
	    (begin
              ;; -(print "wait-for-qif sleeping " delayval " numqrys = " numqrys " fname = " fname)
	      (thread-sleep! delayval)
	      (loop (+ count 1))))))
    (with-output-to-file crumbn
      (lambda ()
	(print fname" run-id="run-id" params="params)
	))
    crumbn))




(define no-condition-db-with-db (make-parameter #t))

;; (db:with-db dbstruct run-id sqlite3:exec "select blah fgrom blaz;")
;; r/w is a flag to indicate if the db is modified by this query #t = yes, #f = no
;;
(define (db:with-db dbstruct run-id r/w proc . params)