From 7f7652202a18967e9379ac51dd619aa016e45cfd Mon Sep 17 00:00:00 2001 From: Sxci Date: Wed, 28 Oct 2020 16:09:23 +0800 Subject: [PATCH 1/3] add default value --- .gitignore | 1 + cmd/cdn.go | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 5aad7ee4..c30f8c8e 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ _testmain.go .idea .vscode +.DS_Store # go test coverage file coverage.txt diff --git a/cmd/cdn.go b/cmd/cdn.go index 4fdfb4d1..0dc2246b 100644 --- a/cmd/cdn.go +++ b/cmd/cdn.go @@ -55,18 +55,18 @@ func init() { cdnRefreshCmd.Flags().BoolVarP(&isDir, "dirs", "r", false, "refresh directory") cdnRefreshCmd.Flags().StringVarP(&prefetchFile, "input-file", "i", "", "input file") - cdnRefreshCmd.Flags().IntVar(&qpsLimit, "qps", 0, "qps limit for http call") - cdnRefreshCmd.Flags().IntVarP(&itemsLimit, "size", "s", 0, "max item-size pre commit") + cdnRefreshCmd.Flags().IntVar(&qpsLimit, "qps", 1, "qps limit for http call") + cdnRefreshCmd.Flags().IntVarP(&itemsLimit, "size", "s", -1, "max item-size pre commit") cdnPreCmd.Flags().StringVarP(&prefetchFile, "input-file", "i", "", "input file") - cdnPreCmd.Flags().IntVar(&qpsLimit, "qps", 0, "qps limit for http call") - cdnPreCmd.Flags().IntVarP(&itemsLimit, "size", "s", 0, "max item-size pre commit") + cdnPreCmd.Flags().IntVar(&qpsLimit, "qps", 1, "qps limit for http call") + cdnPreCmd.Flags().IntVarP(&itemsLimit, "size", "s", -1, "max item-size pre commit") RootCmd.AddCommand(cdnPreCmd, cdnRefreshCmd) } func initOnInitialize() { - logs.Debug("qps limit: %d, max item-size: %d", qpsLimit, itemsLimit) + logs.Debug("init qps limit: %d, max item-size: %d", qpsLimit, itemsLimit) if qpsLimit > 0 { d := time.Second / time.Duration(qpsLimit) timeTicker = time.NewTicker(d) @@ -81,6 +81,13 @@ func acquire() { // 【cdnrefresh】刷新所有CDN节点 func CdnRefresh(cmd *cobra.Command, params []string) { + if itemsLimit == -1 { + if isDir { + itemsLimit = 9 + } else { + itemsLimit = 59 + } + } var urlListFile string if prefetchFile != "" { @@ -132,7 +139,7 @@ func CdnRefresh(cmd *cobra.Command, params []string) { if len(itemsToRefresh) == BATCH_CDN_REFRESH_URLS_ALLOW_MAX || (itemsLimit > 0 && len(itemsToRefresh) >= itemsLimit) { cdnRefresh(cm, itemsToRefresh, nil) - itemsToRefresh = make([]string, 0, 50) + itemsToRefresh = make([]string, 0, 60) } } } @@ -162,6 +169,9 @@ func cdnRefresh(cm *cdn.CdnManager, urls []string, dirs []string) { // 【cdnprefetch】CDN 文件预取 func CdnPrefetch(cmd *cobra.Command, params []string) { + if itemsLimit == -1 { + itemsLimit = 59 + } var urlListFile string if prefetchFile != "" { @@ -186,7 +196,7 @@ func CdnPrefetch(cmd *cobra.Command, params []string) { cm := iqshell.GetCdnManager() scanner := bufio.NewScanner(fp) - urlsToPrefetch := make([]string, 0, 10) + urlsToPrefetch := make([]string, 0, 60) for scanner.Scan() { url := strings.TrimSpace(scanner.Text()) if url == "" { @@ -197,7 +207,7 @@ func CdnPrefetch(cmd *cobra.Command, params []string) { if len(urlsToPrefetch) == BATCH_CDN_PREFETCH_ALLOW_MAX || (itemsLimit > 0 && len(urlsToPrefetch) >= itemsLimit) { cdnPrefetch(cm, urlsToPrefetch) - urlsToPrefetch = make([]string, 0, 10) + urlsToPrefetch = make([]string, 0, 60) } } From 07ac89a9f1ede79e71e2aa5608e76d37c53ceb67 Mon Sep 17 00:00:00 2001 From: Sxci Date: Wed, 28 Oct 2020 16:27:17 +0800 Subject: [PATCH 2/3] add default value --- cmd/cdn.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/cdn.go b/cmd/cdn.go index 0dc2246b..569f0e66 100644 --- a/cmd/cdn.go +++ b/cmd/cdn.go @@ -88,6 +88,7 @@ func CdnRefresh(cmd *cobra.Command, params []string) { itemsLimit = 59 } } + logs.Debug("qps limit: %d, max item-size: %d", qpsLimit, itemsLimit) var urlListFile string if prefetchFile != "" { @@ -172,6 +173,7 @@ func CdnPrefetch(cmd *cobra.Command, params []string) { if itemsLimit == -1 { itemsLimit = 59 } + logs.Debug("qps limit: %d, max item-size: %d", qpsLimit, itemsLimit) var urlListFile string if prefetchFile != "" { From de9f03b10a5a87d36e9cff83af232c89bd09e3d2 Mon Sep 17 00:00:00 2001 From: Sxci Date: Wed, 28 Oct 2020 22:40:08 +0800 Subject: [PATCH 3/3] remove a debug --- cmd/cdn.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/cdn.go b/cmd/cdn.go index 569f0e66..fbe97086 100644 --- a/cmd/cdn.go +++ b/cmd/cdn.go @@ -66,7 +66,6 @@ func init() { } func initOnInitialize() { - logs.Debug("init qps limit: %d, max item-size: %d", qpsLimit, itemsLimit) if qpsLimit > 0 { d := time.Second / time.Duration(qpsLimit) timeTicker = time.NewTicker(d) @@ -88,7 +87,7 @@ func CdnRefresh(cmd *cobra.Command, params []string) { itemsLimit = 59 } } - logs.Debug("qps limit: %d, max item-size: %d", qpsLimit, itemsLimit) + logs.Debug("dir: %v, qps limit: %d, max item-size: %d", isDir, qpsLimit, itemsLimit) var urlListFile string if prefetchFile != "" {