Bloomberg API 请求超时
设置了 ReferenceDataRequest 后,我将其发送到 EventQueue
Service refdata = _session.GetService("//blp/refdata");
Request request = refdata.CreateRequest("ReferenceDataRequest");
// append the appropriate symbol and field data to the request
EventQueue eventQueue = new EventQueue();
Guid guid = Guid.NewGuid();
CorrelationID id = new CorrelationID(guid);
_session.SendRequest(request, eventQueue, id);
long _eventWaitTimeout = 60000;
myEvent = eventQueue.NextEvent(_eventWaitTimeout);
通常我可以从队列中获取消息,但现在我遇到的情况是,如果我在应用程序的同一运行中发出多个请求(通常大约第十个),我看到一个 TIMEOUT
EventType
if (myEvent.Type == Event.EventType.TIMEOUT)
throw new Exception("Timed Out - need to rethink this strategy");
else
msg = myEvent.GetMessages().First();
这些是在同一个线程上进行的,但我假设沿线的某个地方有一些东西我正在消耗而不是释放。
有人有任何线索或建议吗?
关于 BLP API 的 SO 参考并不多,但希望我们可以开始纠正这种情况。
Having set up a ReferenceDataRequest I send it along to an EventQueue
Service refdata = _session.GetService("//blp/refdata");
Request request = refdata.CreateRequest("ReferenceDataRequest");
// append the appropriate symbol and field data to the request
EventQueue eventQueue = new EventQueue();
Guid guid = Guid.NewGuid();
CorrelationID id = new CorrelationID(guid);
_session.SendRequest(request, eventQueue, id);
long _eventWaitTimeout = 60000;
myEvent = eventQueue.NextEvent(_eventWaitTimeout);
Normally I can grab the message from the queue, but I'm hitting the situation now that if I'm making a number of requests in the same run of the app (normally around the tenth), I see a TIMEOUT
EventType
if (myEvent.Type == Event.EventType.TIMEOUT)
throw new Exception("Timed Out - need to rethink this strategy");
else
msg = myEvent.GetMessages().First();
These are being made on the same thread, but I'm assuming that there's something somewhere along the line that I'm consuming and not releasing.
Anyone have any clues or advice?
There aren't many references on SO to BLP's API, but hopefully we can start to rectify that situation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我只是想分享一些东西,感谢您在最初的帖子中包含的代码。
如果您长时间请求历史盘中数据(这会导致 Bloomberg API 生成许多事件),请不要使用 API 文档中指定的模式,因为它最终可能会使您的应用程序检索所有事件的速度非常慢。
基本上,不要在 Session 对象上调用 NextEvent()!请改用专用的 EventQueue。
不要这样做:
这样做:
这可以带来一些性能改进,尽管众所周知 API 不是特别确定......
I just wanted to share something, thanks to the code you included in your initial post.
If you make a request for historical intraday data for a long duration (which results in many events generated by Bloomberg API), do not use the pattern specified in the API documentation, as it may end up making your application very slow to retrieve all events.
Basically, do not call NextEvent() on a Session object! Use a dedicated EventQueue instead.
Instead of doing this:
Do this:
This can result in some performance improvement, though the API is known to not be particularly deterministic...
我并没有真正抽出时间来解决这个问题,但我们确实找到了解决方法。
根据服务器 API 文档中的一条看似一次性的小评论,我们选择创建第二个会话。一个会话负责静态请求,另一个会话负责实时请求。例如,
这意味着一个会话以订阅模式运行,另一个会话则更加同步 - 我认为正是这种二元性才是我们问题的根源。
自从进行更改以来,我们没有遇到任何问题。
I didn't really ever get around to solving this question, but we did find a workaround.
Based on a small, apparently throwaway, comment in the Server API documentation, we opted to create a second session. One session is responsible for static requests, the other for real-time. e.g.
The means one session operates in subscription mode, the other more synchronously - I think it was this duality which was at the root of our problems.
Since making that change, we've not had any problems.
我对文档的阅读同意您需要为“//blp/mktdata”和“//blp/refdata”服务单独的会话。
My reading of the docs agrees that you need separate sessions for the "//blp/mktdata" and "//blp/refdata" services.
一位客户似乎也遇到了类似的问题。我通过创建数百个会话而不是在一个会话中传递数百个请求来解决这个问题。彭博社可能对这种 BFI(暴力和无知)方法不满意,因为我们正在为每次会议发送现场请求,但它确实有效。
A client appeared to have a similar problem. I solved it by making hundreds of sessions rather than passing in hundreds of requests in one session. Bloomberg may not be to happy with this BFI (brute force and ignorance) approach as we are sending the field requests for each session but it works.
很高兴看到 stackoverflow 上的另一个人享受着 Bloomberg API 的痛苦:-)
我很惭愧地说我使用了以下模式(我怀疑是从示例代码中复制的)。它似乎工作得相当稳健,但可能忽略了一些重要的消息。但我不明白你的超时问题。它是 Java,但所有语言的工作原理基本相同。
这可能有效,因为它会消耗每个事件的所有消息。
Nice to see another person on stackoverflow enjoying the pain of bloomberg API :-)
I'm ashamed to say I use the following pattern (I suspect copied from the example code). It seems to work reasonably robustly, but probably ignores some important messages. But I don't get your time-out problem. It's Java, but all the languages work basically the same.
This may work because it consumes all messages off each event.
听起来您一次提出了太多请求。 BB 在任何给定时间只会处理每个连接一定数量的请求。请注意,打开越来越多的连接不会有帮助,因为每个订阅也有限制。如果您同时发出大量耗时的请求,有些请求可能会超时。另外,您应该完全处理请求(直到收到 RESPONSE 消息),或者取消它们。未完成的部分请求会浪费一个槽。由于分成两个会话,似乎对您有所帮助,听起来您也在同时发出大量订阅请求。您是否使用订阅作为拍摄快照的方式?即订阅一个工具,获取初始值,然后取消订阅。如果是这样,您应该尝试寻找不同的设计。这不是订阅的预期使用方式。未完成的订阅请求也使用请求槽。这就是为什么最好在单个订阅列表中批量处理尽可能多的订阅,而不是发出许多单独的请求。希望这对您使用 api 有所帮助。
It sounds like you are making too many requests at once. BB will only process a certain number of requests per connection at any given time. Note that opening more and more connections will not help because there are limits per subscription as well. If you make a large number of time consuming requests simultaneously, some may timeout. Also, you should process the request completely(until you receive RESPONSE message), or cancel them. A partial request that is outstanding is wasting a slot. Since splitting into two sessions, seems to have helped you, it sounds like you are also making a lot of subscription requests at the same time. Are you using subscriptions as a way to take snapshots? That is subscribe to an instrument, get initial values, and de-subscribe. If so, you should try to find a different design. This is not the way the subscriptions are intended to be used. An outstanding subscription request also uses a request slot. That is why it is best to batch as many subscriptions as possible in a single subscription list instead of making many individual requests. Hope this helps with your use of the api.
顺便说一句,我无法从您的示例代码中看出,但是当您被事件队列中的消息阻止时,您是否也在(在单独的事件队列中)读取主事件队列?您必须处理队列外的所有消息,特别是当您有未完成的订阅时。响应可以很快排队。如果您不处理消息,会话可能会达到某些队列限制,这可能就是您超时的原因。此外,如果您不读取消息,您可能会被标记为慢速消费者,并且在开始消费待处理消息之前不会收到更多数据。 api 是异步的。事件队列只是一种阻塞特定请求的方法,而不必在可以阻塞的上下文中处理来自主队列的所有消息,否则很难中断逻辑流以异步处理部分。
By the way, I can't tell from your sample code, but while you are blocked on messages from the event queue, are you also reading from the main event queue while(in a seperate event queue)? You must process all the messages out of the queue, especially if you have outstanding subscriptions. Responses can queue up really fast. If you are not processing messages, the session may hit some queue limits which may be why you are getting timeouts. Also, if you don't read messages, you may be marked a slow consumer and not receive more data until you start consuming the pending messages. The api is async. Event queues are just a way to block on specific requests without having to process all messages from the main queue in a context where blocking is ok, and it would otherwise be be difficult to interrupt the logic flow to process parts asynchronously.