Skip to content

Commit 85b109f

Browse files
committed
remove env maxMemory; default max/2 or 1GB
1 parent 00915a0 commit 85b109f

3 files changed

Lines changed: 15 additions & 23 deletions

File tree

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,14 @@ handle other errors, for example RESOURCE_EXHAUSTED (HTTP 429).
124124

125125
### Memory Configuration
126126

127-
The `SpiceClient` uses an Arrow `RootAllocator` for managing off-heap memory. By default, it allows unlimited memory allocation. To prevent OOM issues in constrained environments, you can limit the maximum memory:
127+
The `SpiceClient` uses an Arrow `RootAllocator` for managing off-heap memory. By default, it limits memory to 50% of the JVM's maximum heap size or 1GB, whichever is lower. To prevent OOM issues in constrained environments, you can limit the maximum memory:
128128

129129
```java
130130
SpiceClient client = SpiceClient.builder()
131131
.withMaxMemory(1024 * 1024 * 1024L) // 1GB limit
132132
.build();
133133
```
134134

135-
You can also set the limit via the `SPICE_MAX_MEMORY` environment variable (in bytes). If both are provided, the builder method takes precedence.
136-
137135
### Spice.ai Runtime commands
138136

139137
#### Accelerated dataset refresh

src/main/java/ai/spice/Config.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,6 @@ public static URI getCloudHttpAddressUri() throws URISyntaxException {
9393
return new URI(CLOUD_HTTP_ADDRESS);
9494
}
9595

96-
/**
97-
* Returns the maximum memory allocation for the Arrow RootAllocator from the
98-
* SPICE_MAX_MEMORY environment variable.
99-
*
100-
* @return the maximum memory in bytes, or Long.MAX_VALUE if not set or invalid.
101-
*/
102-
public static long getMaxMemory() {
103-
try {
104-
String maxMemoryStr = System.getenv("SPICE_MAX_MEMORY");
105-
long maxMemory = Long.parseLong(maxMemoryStr);
106-
if (maxMemory > 0) {
107-
return maxMemory;
108-
}
109-
} catch (Exception e) {
110-
// Any exception, fall back to default
111-
}
112-
return Long.MAX_VALUE;
113-
}
114-
11596
/**
11697
* Returns the Spice SDK user agent for this system, including the package
11798
* version, system OS, version and arch.

src/main/java/ai/spice/SpiceClientBuilder.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ public class SpiceClientBuilder {
4040
private int maxRetries = 3;
4141
private long maxMemory = Long.MAX_VALUE;
4242

43+
/**
44+
* Calculates the default maximum memory for the Arrow RootAllocator.
45+
* Returns 50% of the JVM's maximum heap size or 1GB, whichever is lower.
46+
*
47+
* @return the default maximum memory in bytes.
48+
*/
49+
private static long calculateDefaultMaxMemory() {
50+
long jvmMaxMemory = Runtime.getRuntime().maxMemory();
51+
long halfMemory = jvmMaxMemory / 2;
52+
long oneGB = 1024L * 1024 * 1024;
53+
return Math.min(halfMemory, oneGB);
54+
}
55+
4356
/**
4457
* Constructs a new SpiceClientBuilder instance
4558
*
@@ -48,7 +61,7 @@ public class SpiceClientBuilder {
4861
SpiceClientBuilder() throws URISyntaxException {
4962
this.flightAddress = Config.getLocalFlightAddressUri();
5063
this.httpAddress = Config.getLocalHttpAddressUri();
51-
this.maxMemory = Config.getMaxMemory();
64+
this.maxMemory = calculateDefaultMaxMemory();
5265
}
5366

5467
/**

0 commit comments

Comments
 (0)