事件批处理

云眼About 4 min

事件批处理

本主题介绍云眼灰度发布(特性标帜)AB实验 Ruby SDK 如何使用事件处理器将展示和转化事件批处理到单个有效负载中,然后再将其发送到云眼。

云眼灰度发布(特性标帜)AB实验 Ruby SDK 将决策和转换事件批处理到单个有效负载中,然后再将其发送到云眼。这是通过称为事件处理器的 SDK 组件实现的。

事件批处理的优点是,根据定义、配置和使用事件处理器的方式,减少对云眼灰度发布(特性标帜)AB实验的出站请求数。这意味着跟踪的决策和转化事件数量相同,网络流量会更少。

在 Ruby SDK 中,提供接口的实现和批处理事件。可以根据两个参数控制批处理:BatchEventProcessor``EventProcessor

  • 批大小:定义在发送到云眼灰度发布(特性标帜)AB实验之前一起批处理的事件数。
  • 刷新间隔:定义任何批处理事件应发送到云眼灰度发布(特性标帜)AB实验的时间量。

当批大小达到指定的限制或刷新间隔达到指定的时间限制时,将发送由批处理有效负载组成的事件。 下面将更详细地介绍选项。BatchEventProcessor

基本示例

Rubby

require 'eyeofcloud' require 'eyeofcloud/eyeofcloud_factory' # Initialize an Eyeofcloud client eyeofcloud_instance = Eyeofcloud::EyeofcloudFactory.default_instance( 'put_your_sdk_key_here' )

默认情况下,批大小为 10,刷新间隔为 30 秒。

高级示例

使用 BatchEventProcessor 的构造函数设置批大小和刷新间隔。

Rubby

require 'eyeofcloud' require 'eyeofcloud/event/batch_event_processor' # Initialize BatchEventProcessor event_processor = Eyeofcloud::BatchEventProcessor.new( event_dispatcher: event_dispatcher, batch_size: 50, flush_interval: 1000 ) # Initialize an Eyeofcloud client eyeofcloud_client = Eyeofcloud::Project.new( datafile, event_dispatcher, logger, error_handler, skip_json_validation, user_profile_service, sdk_key, config_manager, notification_center, event_processor )

批处理事件处理器

BatchEventProcessor 是事件批处理位置的实现。该类维护单个使用者线程,该线程从 中提取事件,并在将结果发送到 和 之前缓冲这些事件,以达到配置的批大小或最大持续时间。EventProcessor``queue``LogEvent``EventDispatcher``NotificationCenter

以下属性可用于自定义配置。BatchEventProcessor

财产

默认值

描述

event_queue

1000秒<>

SsizeQueue.new(100) 或 Queue.new
对要由执行程序批处理和调度的各个事件进行排队。
默认值为 1000。

event_dispatcher

用于将事件有效负载调度到云眼灰度发布(特性标帜)AB实验。

batch_size

10秒<>

调度前要批处理的最大事件数。达到此数字后,将刷新所有排队的事件并将其发送到云眼灰度发布(特性标帜)AB实验。

flush_interval

30000

Maximum time to wait before batching and dispatching events. In milliseconds.

notification_center

nil

Notification center instance to be used to trigger any notifications.

For more information, see Initialize SDK.

Side effects

The table lists other Eyeofcloud灰度发布(特性标帜) functionality that may be triggered by using this class.

Functionality

Description

LogEvent

Whenever the event processor produces a batch of events, a LogEvent object will be created using EventFactory.
It contains batch of conversion and decision events.
This object will be dispatched using the provided event dispatcher and also it will be sent to the notification subscribers

Notification Listeners

Flush invokes the LOG_EVENT notification listener if this listener is subscribed to.

Registering LogEvent listener

To register a LogEvent notification listener

Ruby

callback_reference = lambda do |*args| puts "Notified!" end eyeofcloud_client.notification_center.add_notification_listener( Eyeofcloud::NotificationCenter::NOTIFICATION_TYPES[:LOG_EVENT], callback_reference )

LogEvent

LogEvent object gets created using EventFactoryopen in new window. It represents the batch of decision and conversion events we send to the Eyeofcloud Feature Experimentation backend.

Object

Type

Description

http_verb
Required (non null)

String

The HTTP verb to use when dispatching the log event. It can be Get or Post.

url
Required (non null)

String

URL to dispatch log event to.

参数必需(非空)

事件批处理

它包含有关批处理的每个事件的所有信息。包括包含用户事件的访问者列表。

必需
标头

散 列

请求标头。

在应用程序退出时关闭云眼灰度发布(特性标帜)AB实验

如果启用事件批处理,则必须在退出之前调用该方法。这可确保尽快刷新排队的事件,以避免数据丢失。close``eyeofcloud.close()

警告

由于 Eyeofcloud 客户端维护排队事件的缓冲区,因此必须在关闭应用程序之前或在取消引用实例时调用 Eyeofcloud 功能实验实例。close()

方法

描述

关闭()

停止所有计时器并刷新事件队列。此方法还将停止数据文件管理器发生的任何计时器。

注意:我们建议将此方法连接到正在运行的进程的终止信号。

Last update:
Contributors: “zhangweixue”,zhangweixue