Skip to content

Commit c1e4de7

Browse files
committed
fix: update README with threading and batching examples [skip-ci]
1 parent 2762610 commit c1e4de7

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

CHANGELOG.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.9.0] - 2025-05-06
8+
9+
### Added
10+
11+
- Added support for `batch_event_data` configuration to optimize network requests by batching multiple events together. This allows you to:
12+
13+
- Configure `request_time_interval` to flush events after a specified time interval
14+
- Set `events_per_request` to control maximum events per batch
15+
- Implement `flush_callback` to handle batch processing results
16+
- Manually trigger event flushing via `flush_events()` method
17+
18+
```python
19+
from vwo import init
20+
21+
def event_flush_callback(error, payload):
22+
# your implementation here
23+
24+
options = {
25+
'sdk_key': '32-alpha-numeric-sdk-key', # SDK Key
26+
'account_id': '123456', # VWO Account ID
27+
'batch_event_data': {
28+
'events_per_request': 60, # Send up to 100 events per request
29+
'request_time_interval': 100, # Flush events every 60 seconds
30+
'flush_callback': event_flush_callback
31+
}
32+
}
33+
34+
vwo_client = init(options)
35+
```
36+
37+
- You can also manually flush events using the `flush_events()` method:
38+
```python
39+
vwo_client.flush_events()
40+
```
41+
742
## [1.8.0] - 2025-04-22
843

944
### Added

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ To customize the SDK further, additional parameters can be passed to the `init()
6363
| `storage` | Custom storage connector for persisting user decisions and campaign data. data. | No | Dictionary | See [Storage](#storage) section |
6464
| `logger` | Toggle log levels for more insights or for debugging purposes. You can also customize your own transport in order to have better control over log messages. | No | Dictionary | See [Logger](#logger) section |
6565
| `integrations` | Callback function for integrating with third-party analytics services. | No | Function | See [Integrations](#integrations) section |
66+
| `batch_event_data` | Configuration for batch event processing to optimize network requests | No | Dictionary | See [Batch Events](#batch-events) section |
67+
| `threading` | Toggle threading for better (enabled by default) performance. | No | Dictionary | See [Threading](#threading) section |
6668

6769
### User Context
6870

@@ -367,6 +369,104 @@ options = {
367369
vwo_client = init(options)
368370
```
369371

372+
### Threading
373+
374+
The SDK leverages threading to efficiently manage concurrent operations. Threading is enabled by default, but can be disabled by configuring the `threading` parameter during initialization. This gives you control over the SDK's concurrency behavior based on your application's needs.
375+
376+
| Parameter | Description | Required | Type | Default |
377+
| --------- | ----------- | -------- | ---- | ------- |
378+
| `enabled` | Enable or disable threading. | No | Boolean | `true` |
379+
| `max_workers` | Maximum number of threads to use. | No | Integer | `5` |
380+
381+
#### Disable Threading
382+
383+
When threading is disabled, all tracking calls will block the main execution thread until they complete. This means your application will wait for each VWO operation before continuing.
384+
385+
Example showing blocking behavior:
386+
387+
```python
388+
# By disabling threading, the SDK will wait for the response from the server for each tracking call.
389+
from vwo import init
390+
391+
options = {
392+
'sdk_key': '32-alpha-numeric-sdk-key', # SDK Key
393+
'account_id': '123456', # VWO Account ID
394+
'threading': {
395+
'enabled': False
396+
}
397+
}
398+
399+
vwo_client = init(options)
400+
```
401+
402+
#### Enable Threading (Default)
403+
404+
Threading in the VWO SDK provides several important benefits:
405+
406+
1. **Asynchronous Event Tracking**: When enabled, all tracking calls are processed asynchronously in the background. This prevents these network calls from blocking your application's main execution flow.
407+
408+
2. **Improved Performance**: By processing tracking and network operations in separate threads, your application remains responsive and can continue serving user requests without waiting for VWO operations to complete.
409+
410+
Example of how threading improves performance:
411+
- Without threading: Each tracking call blocks until the server responds
412+
- With threading: Tracking calls return immediately while processing happens in background
413+
414+
The SDK uses a thread pool to manage these concurrent operations efficiently. The default pool size of 5 threads is suitable for most applications, but you can adjust it based on your needs:
415+
416+
```python
417+
# By default, threading is enabled and the max_workers is set to 5.
418+
# you can customize the max_workers by passing the max_workers parameter in the threading configuration.
419+
from vwo import init
420+
421+
options = {
422+
'sdk_key': '32-alpha-numeric-sdk-key', # SDK Key
423+
'account_id': '123456', # VWO Account ID
424+
'threading': {
425+
'enabled': True,
426+
'max_workers': 10
427+
}
428+
}
429+
430+
vwo_client = init(options)
431+
```
432+
433+
### Batch Events
434+
435+
The `batch_event_data` configuration allows you to optimize network requests by batching multiple events together. This is particularly useful for high-traffic applications where you want to reduce the number of API calls.
436+
437+
| **Parameter** | **Description** | **Required** | **Type** | **Default** |
438+
| --------------------- | ----------------------------------------------------------------------- | ------------ | -------- | ----------- |
439+
| `request_time_interval` | Time interval (in seconds) after which events are flushed to the server | No | Number | `600` |
440+
| `events_per_request` | Maximum number of events to batch together before sending to the server | No | Number | `100` |
441+
| `flush_callback` | Callback function to be executed after events are flushed | No | Function | See example |
442+
443+
Example usage:
444+
445+
```python
446+
from vwo import init
447+
448+
def event_flush_callback(error, payload):
449+
# your implementation here
450+
451+
options = {
452+
'sdk_key': '32-alpha-numeric-sdk-key', # SDK Key
453+
'account_id': '123456', # VWO Account ID
454+
'batch_event_data': {
455+
'events_per_request': 60, # Send up to 100 events per request
456+
'request_time_interval': 100, # Flush events every 60 seconds
457+
'flush_callback': event_flush_callback
458+
}
459+
}
460+
461+
vwo_client = init(options)
462+
```
463+
464+
You can also manually flush events using the `flush_events()` method:
465+
466+
```python
467+
vwo_client.flush_events()
468+
```
469+
370470
## Local development
371471

372472
```bash

0 commit comments

Comments
 (0)