iPhone iOS how to implement a sequence of background network send operations in the fastest way possible? -


i'm trying stream data server @ regular intervals , in way fast , not block ui. ui pretty busy trying display data. implementation uses nstimer fires every 50ms, picks network packet out of circular array , sends over:

//this timer       networkwritetimer = [nstimer scheduledtimerwithtimeinterval:0.05 target:self selector:@selector(sendactivity:)  userinfo:nil repeats:yes];       -(void)sendactivityinbackground:(id)sender     {          [[appconfig getinstance].activeremoteroom.connection sendnetworkpacket:[circulararray objectatindex:arrayindex%arraycapacity]];     }       -(void)sendactivity:(nstimer*)timer     {          // send out         [self performselectorinbackground:@selector(sendactivityinbackground:) withobject:nil];      } 

i'm not satisfied performance of method. time profiling has revealed there's overhead associated performing background selectors, , performance can quite choppy.

i'm thinking of additional ways improve performance:

  • improve performance of current timer based code
  • try grand central dispatch
  • implement nsoperationsqueue single operation.
  • use dedicated thread wakes up, checks update , sends on if needed

ideally, send data @ faster intervals (10ms or each activity update). poses question: what fastest way implement sequence of background send requests, order matters? want make sure 1 packet gets send before next 1 being sent.

try recurring dispatch timer (that part of gcd):

self.synchronizerqueue = dispatch_queue_create("synchronizer queue", dispatch_queue_serial); self.synchronizetimer = dispatch_source_create(dispatch_source_type_timer, 0, 0, self.synchronizerqueue); dispatch_source_set_timer(self.synchronizetimer, dispatch_time_now, nsec_per_msec * 10, nsec_per_msec * 1); dispatch_source_set_event_handler(self.synchronizetimer, ^ {    // processing here }); dispatch_resume(self.synchronizetimer); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -