c# - How to reuse TCP connections with .NET BigQuery API? -


i'm streaming data bq .net api. , noticed in process explorer new tcp/ip connections created , ended on , on again. i'm wondering if it's possible reuse connection , avoid big overhead of connection creation , end?

    public async task insertasync(basebigquerytable table, ilist<idictionary<string, object>> rowlist, getbqinsertidfunction getinsert,cancellationtoken ct)     {         if (rowlist.count == 0)         {             return;         }         string tableid = table.tableid;         ilist<tabledatainsertallrequest.rowsdata> requestrows = rowlist.select(row => new tabledatainsertallrequest.rowsdata {json = row,insertid = getinsert(row)}).tolist();         tabledatainsertallrequest request = new tabledatainsertallrequest { rows = requestrows };                    bool needcreatetable = false;         bigqueryservice bqservice = null;         try         {             bqservice = getbigqueryservice();                             tabledatainsertallresponse response =                 await                     bqservice.tabledata.insertall(request, _account.projectid, table.datasetid, tableid)                         .executeasync(ct);                            ilist<tabledatainsertallresponse.inserterrorsdata> inserterrors = response.inserterrors;             if (inserterrors != null && inserterrors.count > 0)             {                 //handling errors, removed easier reading..             }         }catch{            //... removed easier reading         }                 {             if (bqservice != null)                 bqservice.dispose();         }        }  private bigqueryservice getbigqueryservice() {    return new bigqueryservice(new baseclientservice.initializer    {        httpclientinitializer = _credential,        applicationname = _applicationname,    }); } 

** follow up **

the answer given below seems solution reduce http connections. however, found using batch request on large mount of live data streaming have limitation. see questions on this: google api batchrequest: established connection aborted software in host machine

below link documents how batch api calls reduce number of http connections client has make

https://cloud.google.com/bigquery/batch

after batch request issued, can response , parse out involved jobids. alternative can preset jobids in batch request each , every inner request. note: need make sure jobids unique

after can check going on each of these jobs via jobs.get https://cloud.google.com/bigquery/docs/reference/v2/jobs/get


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -