13
13
#define PC_JSON_MISSING_PERMS -32001
14
14
#define PC_JSON_NOT_READY -32002
15
15
#define PC_BATCH_SEND_FAILED -32010
16
+ // Flush partial batches if not completed within 400 ms.
17
+ #define PC_FLUSH_INTERVAL (400L *PC_NSECS_IN_MSEC)
16
18
17
19
using namespace pc ;
18
20
@@ -34,6 +36,7 @@ user::user()
34
36
hsvr_.set_net_connect ( this );
35
37
hsvr_.set_ws_parser ( this );
36
38
set_net_parser ( &hsvr_ );
39
+ last_upd_ts_ = get_now ();
37
40
}
38
41
39
42
void user::set_rpc_client ( rpc_client *rptr )
@@ -332,15 +335,24 @@ void user::parse_get_product( uint32_t tok, uint32_t itok )
332
335
333
336
void user::send_pending_upds ()
334
337
{
335
- if ( pending_vec_.empty () ) {
338
+ uint32_t n_to_send = 0 ;
339
+ int64_t curr_ts = get_now ();
340
+ if (curr_ts - last_upd_ts_ > PC_FLUSH_INTERVAL) {
341
+ n_to_send = pending_vec_.size ();
342
+ } else if (pending_vec_.size () >= sptr_->get_max_batch_size ()) {
343
+ n_to_send = sptr_->get_max_batch_size ();
344
+ }
345
+
346
+ if (n_to_send == 0 ) {
336
347
return ;
337
348
}
338
349
339
- if ( !price::send ( pending_vec_.data (), pending_vec_. size () ) ) {
350
+ if ( !price::send ( pending_vec_.data (), n_to_send ) ) {
340
351
add_error ( 0 , PC_BATCH_SEND_FAILED, " batch send failed - please check the pyth logs" );
341
352
}
342
353
343
- pending_vec_.clear ();
354
+ pending_vec_.erase (pending_vec_.begin (), pending_vec_.begin () + n_to_send);
355
+ last_upd_ts_ = curr_ts;
344
356
}
345
357
346
358
void user::parse_get_all_products ( uint32_t itok )
0 commit comments