• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Strange Delay
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange Delay


  • Subject: Re: Strange Delay
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Thu, 31 Mar 2016 11:08:15 +0700

> On 30 Mar 2016, at 18:35, Ken Thomases <email@hidden> wrote:
>
> On Mar 30, 2016, at 1:44 AM, Gerriet M. Denkmann <email@hidden> wrote:
>>
>> This is done once (OS X 10.10.5):
>> commonSendQueue = dispatch_queue_create( “common socket queue", DISPATCH_QUEUE_SERIAL);
>>
>> Several objects do this quite often:
>>
>> NSDate *dax0 = [ NSDate date ];
>> dispatch_async(commonSendQueue, ^{ @autoreleasepool { [ someOtherObject doSomethingwithDate: dax0]; }});
>>
>> double delay1 = 50 msec
>
> What does this mean?  That's not valid code.  What’s the "msec" doing in there?

Sorry about this confusing pseudo code. The actual code is:

double delay1 = 50 * 1e-3;	//	50 msec in units of second


>> dispatch_after(disTim1, commonSendQueue, ^{ @autoreleasepool  { [ someOtherObject doSomethingwithDate: dax1]; }});
>>
>>
>> someOtherObject does:
>> - (void) doSomethingwithDate: (NSDate *)date
>> {
>> 	NSTimeInterval inDelay = -date.timeIntervalSinceNow * 1e3;
>> 	if ( inDelay > 12 ) NSLog(@"%s  in-delay %9.3f msec",__FUNCTION__, inDelay);
>> }
>>
>> The in-delay is usually less than a dozen milliseconds.
>>
>> But in the call with dispatch_after (never with dispatch_async) the in-daly is sometimes is 10 seconds - sometimes even 20 or 30 seconds - mostly (but not always) near an integral multiple of 10 seconds.
>>
>> Why this delay of 10 seconds, and how can I find out, what is the cause of it?
>
>> P.S. instead of dispatch_after I tried NSTimer and nanosleep. Same problem.
>
> This may have something to do with App Nap or timer coalescing.

Well, this might explain a shift in a timer doing its stuff by a small amount. Seems unlikely to explain a delay of several 10s of seconds.

> Is your app otherwise active during those delays?

It is constantly sending messages to someOtherObjects and these someOtherObjects send back messages.

Each someOtherObject creates (at init) a sequential queue (socketQueue) and two socket descriptors (socket4FD  and socket6FD for ipv4 and ipv6 respectively) and binds these to some host/port; then does:
dispatch_source_create(DISPATCH_SOURCE_TYPE_WRITE, socket4FD, 0, socketQueue);
same for DISPATCH_SOURCE_TYPE_READ;
then adds dispatch_source_set_event_handlers for each dispatch_source.
Same for socket6FD.

But all activity of these someOtherObjects (which b.t.w. are a modified version of GCDAsyncUdpSocket) is done on its own sequential queue (socketQueue), which is ≠ commonSendQueue.
In sending back massages someOtherObject uses the main queue.

So it really should not have anything to do with the delay in commonSendQueue.

I just checked: same problem with 10.11.4.

Kind regards,

Gerriet.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Strange Delay (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Strange Delay (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: How to find the file (url) that was double-clicked to open my Cocoa Application?
  • Next by Date: Right click context menu
  • Previous by thread: Re: Strange Delay
  • Next by thread: Re: Strange Delay
  • Index(es):
    • Date
    • Thread