You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+164Lines changed: 164 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -286,6 +286,170 @@ Request-level metadata is included in the `IngestRequest` and can be useful for:
286
286
- Debugging and auditing data imports
287
287
- Adding contextual information for downstream processing
288
288
289
+
### Message chunking
290
+
291
+
When ingesting large datasets, you may encounter gRPC message size limits (typically 4 MB). The SDK provides automatic message chunking to split large entity lists into size-appropriate chunks that stay within these limits.
292
+
293
+
#### Automatic chunking
294
+
295
+
Enable chunking by using `WithChunking()` when calling `Ingest`:
296
+
297
+
```go
298
+
package main
299
+
300
+
import (
301
+
"context"
302
+
"fmt"
303
+
"log"
304
+
305
+
"github.com/netboxlabs/diode-sdk-go/diode"
306
+
)
307
+
308
+
funcmain() {
309
+
client, err:= diode.NewClient(
310
+
"grpc://localhost:8080/diode",
311
+
"example-app",
312
+
"0.1.0",
313
+
diode.WithClientID("YOUR_CLIENT_ID"),
314
+
diode.WithClientSecret("YOUR_CLIENT_SECRET"),
315
+
)
316
+
if err != nil {
317
+
log.Fatal(err)
318
+
}
319
+
320
+
// Create a large number of entities
321
+
entities:=make([]diode.Entity, 0)
322
+
fori:=0; i < 10000; i++ {
323
+
entities = append(entities, &diode.Device{
324
+
Name: diode.String(fmt.Sprintf("Device %d", i)),
325
+
Site: &diode.Site{
326
+
Name: diode.String("Site ABC"),
327
+
},
328
+
DeviceType: &diode.DeviceType{
329
+
Model: diode.String("Device Type A"),
330
+
},
331
+
Role: &diode.DeviceRole{
332
+
Name: diode.String("Role ABC"),
333
+
},
334
+
})
335
+
}
336
+
337
+
// Use chunking with default 3.0 MB chunk size
338
+
resp, err:= client.Ingest(
339
+
context.Background(),
340
+
entities,
341
+
diode.WithChunking(0), // 0 = use default
342
+
)
343
+
if err != nil {
344
+
log.Fatal(err)
345
+
}
346
+
log.Printf("Success\n")
347
+
}
348
+
```
349
+
350
+
#### Custom chunk size
351
+
352
+
You can specify a custom chunk size in megabytes:
353
+
354
+
```go
355
+
// Use 3.5 MB chunks instead of the default 3.0 MB
356
+
resp, err:= client.Ingest(
357
+
context.Background(),
358
+
entities,
359
+
diode.WithChunking(3.5),
360
+
)
361
+
```
362
+
363
+
#### Manual chunking
364
+
365
+
For more control, you can manually chunk entities using the `CreateMessageChunks` function:
The chunking algorithm uses greedy bin-packing to efficiently group entities:
445
+
446
+
1. It accumulates entities until adding the next one would exceed the size limit
447
+
2. When the limit would be exceeded, it starts a new chunk
448
+
3. Each chunk includes the base overhead of an `IngestRequest` protobuf message
449
+
4. Entity order is preserved across chunks
450
+
451
+
The default chunk size of 3.0 MB provides a safe margin below the gRPC 4 MB message size limit, accounting for protobuf serialization overhead and network protocol overhead.
452
+
289
453
### TLS verification and certificates
290
454
291
455
TLS verification is controlled by the target URL scheme:
0 commit comments