Event batching for the Flutter SDK
The Optimizely Feature Experimentation Flutter SDK uses the event processor to batch decisions and conversion events into a single payload before sending it to Optimizely Feature Experimentation.
The Flutter SDK lets you batch events and includes options to set an event batch size, event time interval and event flush interval. The benefit of event batching is less network traffic for the same number of impression and conversion events tracked.
Configure event batching
There are three options to configure event batching: eventBatchSize
, eventTimeInterval
and eventMaxQueueSize
. You can pass in both options during client creation. The system holds events in a queue until either:
- The number of events reaches the defined
eventBatchSize
. - The oldest event has been in the queue for longer than the defined
eventTimeInterval
, which is specified in seconds. The system then flushes the queue and sends all queued events to Optimizely Feature Experimentation in a single network request. - The system receives a new datafile revision. This occurs only when you enable live datafile updates.
var flutterSDK = OptimizelyFlutterSdk("<Your_SDK_Key>",
eventOptions: const EventOptions(
batchSize: 1, timeInterval: 60, maxQueueSize: 10000));
var response = await flutterSDK.initializeClient();
The following table defines these options and lists the default settings. Contact support for recommendations for your specific implementation.
Name | Default value | Description |
---|---|---|
eventBatchSize | 10 | The maximum number of events to hold in the queue. Once you reach this number, the system flushes all queued events and sends them to Optimizely Feature Experimentation. |
eventTimeInterval | 1 minute | The maximum duration in milliseconds that an event can exist in the queue before flushing. |
eventMaxQueueSize | 10000 | The maximum queue size in kilobytes. |
Warning
The maximum payload size is 3.5 MB. If the resulting batch payload exceeds this limit, the system rejects requests with a 400 response code,
Bad Request Error
.The size limitation is because of the Optimizely Events API, which Feature Experimentation uses to send data to Optimizely.
The most common cause of a large payload size is a high batch size. If your payloads exceed the size limit, try configuring a smaller batch size.
Close Optimizely Feature Experimentation on application exit
If you enable event batching, you must call the Close method (flutterSDK.close
) before exiting. This ensures that the system flushes queued events as soon as possible to avoid data loss.
Warning
Because the Optimizely client maintains a buffer of queued events, we recommend you call
close()
on the Optimizely Feature Experimentation Flutter SDK instance before shutting down your application or whenever dereferencing the instance.
Method | Description |
---|---|
close() | Stops all timers and flushes the event queue. This method also stops any timers that are happening for the datafile manager. Note: Optimizely recommends connecting this method to a kill signal for the running process. |
You can hook into the SIGTERM
event to ensure that close()
is invoked, guaranteeing the system sends all events in the queue.
flutterSDK.close();
Updated about 1 year ago