public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/ollama] rawhide: Make the download and upload tunable by enviromental variables.
@ 2026-07-12 13:19 Tom Rix
  0 siblings, 0 replies; only message in thread
From: Tom Rix @ 2026-07-12 13:19 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : rpms/ollama
            Branch : rawhide
            Commit : 451e22a8709676a97f545c7e3a434390882c47d2
            Author : Tom Rix <Tom.Rix@amd.com>
            Date   : 2026-07-12T06:18:45-07:00
            Stats  : +194/-0 in 2 file(s)
            URL    : https://src.fedoraproject.org/rpms/ollama/c/451e22a8709676a97f545c7e3a434390882c47d2?branch=rawhide

            Log:
            Make the download and upload tunable by enviromental variables.

Signed-off-by: Tom Rix <Tom.Rix@amd.com>

---
diff --git a/0001-feat-server-make-download-and-upload-parameters-conf.patch b/0001-feat-server-make-download-and-upload-parameters-conf.patch
new file mode 100644
index 0000000..c23c6a2
--- /dev/null
+++ b/0001-feat-server-make-download-and-upload-parameters-conf.patch
@@ -0,0 +1,165 @@
+From 626d5fc6e550e038125415acb2d84c91a957fa8d Mon Sep 17 00:00:00 2001
+From: Tom Rix <Tom.Rix@amd.com>
+Date: Sat, 11 Jul 2026 14:53:44 -0700
+Subject: [PATCH] feat(server): make download and upload parameters
+ configurable via environment variables
+
+Previously, the number of parts and their sizes were hardcoded constants in both the download and upload modules.
+This made it difficult to tune behavior for different network conditions (e.g., slower networks, corporate proxies, or high-speed connections).
+
+This change introduces the following new environment variables:
+
+For downloads:
+* `OLLAMA_NUM_DOWNLOAD_PARTS`: Sets the number of parallel download parts (default 16).
+* `OLLAMA_MIN_DOWNLOAD_PART_SIZE`: Sets the minimum chunk size (e.g., "100MB").
+* `OLLAMA_MAX_DOWNLOAD_PART_SIZE`: Sets the maximum chunk size (e.g., "1GB").
+
+For uploads:
+* `OLLAMA_NUM_UPLOAD_PARTS`: Sets the number of parallel upload parts (default 16).
+* `OLLAMA_MIN_UPLOAD_PART_SIZE`: Sets the minimum chunk size (e.g., "100MB").
+* `OLLAMA_MAX_UPLOAD_PART_SIZE`: Sets the maximum chunk size (e.g., "1GB").
+
+Users can now adjust these values to optimize download/upload performance or work around network issues without recompiling the code. The existing defaults are preserved.
+---
+ server/download.go | 61 +++++++++++++++++++++++++++++++++++++++++-----
+ server/upload.go   | 26 ++++++++++++++++++--
+ 2 files changed, 79 insertions(+), 8 deletions(-)
+
+diff --git a/server/download.go b/server/download.go
+index 0019fa13ac8d..9c0ca1a769e9 100644
+--- a/server/download.go
++++ b/server/download.go
+@@ -36,6 +36,59 @@ var (
+ 	errMaxRedirectsExceeded = errors.New("maximum redirects exceeded (10) for directURL")
+ )
+ 
++var (
++	numDownloadParts          = 16
++	minDownloadPartSize int64 = 100 * format.MegaByte
++	maxDownloadPartSize int64 = 1000 * format.MegaByte
++)
++
++func init() {
++	loadDownloadConfig()
++}
++
++func loadDownloadConfig() {
++	if v := os.Getenv("OLLAMA_NUM_DOWNLOAD_PARTS"); v != "" {
++		if n, err := strconv.Atoi(v); err == nil && n > 0 {
++			numDownloadParts = n
++		}
++	}
++	if v := os.Getenv("OLLAMA_MIN_DOWNLOAD_PART_SIZE"); v != "" {
++		if size, err := parseHumanByte(v); err == nil {
++			minDownloadPartSize = size
++		}
++	}
++	if v := os.Getenv("OLLAMA_MAX_DOWNLOAD_PART_SIZE"); v != "" {
++		if size, err := parseHumanByte(v); err == nil {
++			maxDownloadPartSize = size
++		}
++	}
++}
++
++func parseHumanByte(s string) (int64, error) {
++	s = strings.ToUpper(s)
++	suffixes := map[string]float64{
++		"TB": 1024 * 1024 * 1024 * 1024,
++		"GB": 1024 * 1024 * 1024,
++		"MB": 1024 * 1024,
++		"KB": 1024,
++	}
++	for suffix, multiplier := range suffixes {
++		if strings.HasSuffix(s, suffix) {
++			valStr := strings.TrimSuffix(s, suffix)
++			val, err := strconv.ParseFloat(valStr, 64)
++			if err != nil {
++				return 0, err
++			}
++			return int64(val * float64(multiplier)), nil
++		}
++	}
++	val, err := strconv.ParseInt(s, 10, 64)
++	if err == nil {
++		return val, nil
++	}
++	return 0, fmt.Errorf("cannot parse %s", s)
++}
++
+ var blobDownloadManager sync.Map
+ 
+ type blobDownload struct {
+@@ -96,11 +149,7 @@ func (p *blobDownloadPart) UnmarshalJSON(b []byte) error {
+ 	return nil
+ }
+ 
+-const (
+-	numDownloadParts          = 16
+-	minDownloadPartSize int64 = 100 * format.MegaByte
+-	maxDownloadPartSize int64 = 1000 * format.MegaByte
+-)
++
+ 
+ func (p *blobDownloadPart) Name() string {
+ 	return strings.Join([]string{
+@@ -153,7 +202,7 @@ func (b *blobDownload) Prepare(ctx context.Context, requestURL *url.URL, opts *r
+ 
+ 		b.Total, _ = strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64)
+ 
+-		size := b.Total / numDownloadParts
++		size := b.Total / int64(numDownloadParts)
+ 		switch {
+ 		case size < minDownloadPartSize:
+ 			size = minDownloadPartSize
+diff --git a/server/upload.go b/server/upload.go
+index 35a32c6797ed..f416f6aa1f31 100644
+--- a/server/upload.go
++++ b/server/upload.go
+@@ -46,12 +46,34 @@ type blobUpload struct {
+ 	references atomic.Int32
+ }
+ 
+-const (
++var (
+ 	numUploadParts          = 16
+ 	minUploadPartSize int64 = 100 * format.MegaByte
+ 	maxUploadPartSize int64 = 1000 * format.MegaByte
+ )
+ 
++func init() {
++	loadUploadConfig()
++}
++
++func loadUploadConfig() {
++	if v := os.Getenv("OLLAMA_NUM_UPLOAD_PARTS"); v != "" {
++		if n, err := strconv.Atoi(v); err == nil && n > 0 {
++			numUploadParts = n
++		}
++	}
++	if v := os.Getenv("OLLAMA_MIN_UPLOAD_PART_SIZE"); v != "" {
++		if size, err := parseHumanByte(v); err == nil {
++			minUploadPartSize = size
++		}
++	}
++	if v := os.Getenv("OLLAMA_MAX_UPLOAD_PART_SIZE"); v != "" {
++		if size, err := parseHumanByte(v); err == nil {
++			maxUploadPartSize = size
++		}
++	}
++}
++
+ func (b *blobUpload) Prepare(ctx context.Context, requestURL *url.URL, opts *registryOptions) error {
+ 	p, err := manifest.BlobsPath(b.Digest)
+ 	if err != nil {
+@@ -91,7 +113,7 @@ func (b *blobUpload) Prepare(ctx context.Context, requestURL *url.URL, opts *reg
+ 		return nil
+ 	}
+ 
+-	size := b.Total / numUploadParts
++	size := b.Total / int64(numUploadParts)
+ 	switch {
+ 	case size < minUploadPartSize:
+ 		size = minUploadPartSize
+-- 
+2.53.0
+

diff --git a/ollama.service b/ollama.service
index 36edc13..5c4d9dd 100644
--- a/ollama.service
+++ b/ollama.service
@@ -23,6 +23,35 @@ Environment="OLLAMA_HOST=127.0.0.1:11434"
 # So iGPU will be used
 Environment="OLLAMA_IGPU_ENABLE=1"
 
+# Variables for controlling downloads
+# --------------------------------------------------------------------------
+# OPTION 1: DEFAULT (Original Ollama Baseline)
+# Best for: General purpose use, balanced performance vs stability
+# --------------------------------------------------------------------------
+# Environment="OLLAMA_NUM_DOWNLOAD_PARTS=16"
+# Environment="OLLAMA_MIN_DOWNLOAD_PART_SIZE=100MB"
+# Environment="OLLAMA_MAX_DOWNLOAD_PART_SIZE=1000MB"
+
+# --------------------------------------------------------------------------
+# OPTION 2: MINIMAL / CONSERVATIVE (Slow, Unstable, or Restrictive Networks)
+# Best for: Corporate proxies, flaky connections, low RAM, HDD storage,
+# or registry rate-limits concurrent connections (often caps at 4-8)
+# --------------------------------------------------------------------------
+# Environment="OLLAMA_NUM_DOWNLOAD_PARTS=1"
+# Environment="OLLAMA_MIN_DOWNLOAD_PART_SIZE=1MB"
+# Environment="OLLAMA_MAX_DOWNLOAD_PART_SIZE=1MB"
+
+# --------------------------------------------------------------------------
+# OPTION 3: MAXIMUM / AGGRESSIVE (High-Bandwidth, Modern Network/SSD)
+# Best for: Fiber/cable broadband, low-latency environments, high-I/O SSDs,
+# and registries that allow high concurrency. Avoids "thundering herd"
+# stalls on fast pipes by using larger chunks.
+# --------------------------------------------------------------------------
+# Environment="OLLAMA_NUM_DOWNLOAD_PARTS=32"
+# Environment="OLLAMA_MIN_DOWNLOAD_PART_SIZE=256MB"
+# Environment="OLLAMA_MAX_DOWNLOAD_PART_SIZE=2GB"
+
+
 ExecStart=/usr/bin/ollama serve
 User=ollama
 Group=ollama

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-12 13:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-12 13:19 [rpms/ollama] rawhide: Make the download and upload tunable by enviromental variables Tom Rix

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox