Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a flushInterval configuration option #767

Merged
merged 2 commits into from
Jul 16, 2018

Conversation

fathyb
Copy link
Contributor

@fathyb fathyb commented Jul 13, 2018

Ref: LIB-443

@fathyb fathyb requested a review from f2prateek July 13, 2018 13:50
@codecov-io
Copy link

codecov-io commented Jul 13, 2018

Codecov Report

Merging #767 into master will increase coverage by 0.16%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #767      +/-   ##
==========================================
+ Coverage   85.54%   85.71%   +0.16%     
==========================================
  Files          52       52              
  Lines        2588     2618      +30     
==========================================
+ Hits         2214     2244      +30     
  Misses        374      374

@@ -109,17 +109,44 @@ - (id)initWithAnalytics:(SEGAnalytics *)analytics httpClient:(SEGHTTPClient *)ht
if ([NSThread isMainThread]) {
[self setupFlushTimer];
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is interesting. After updating Xcode I started getting random deadlocks when testing, even on a clean repo on origin/master without any changes and DerivedData nuked.

The debugger showed that two threads (main and our serial queue) are locking the main queue :
screen shot 2018-07-13 at 14 13 34
screen shot 2018-07-13 at 14 13 47

Because we just need to set the timer to let ARC keep a reference on it I replaced the code to use async  instead of sync, which should prevent any deadlock on this section. What do you think @f2prateek?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think we've gone back and forth on this. I can try digging up the history, you might be able to find it via git blame as well.

[self setupFlushTimer];
});
}

// Observe changes to flushInterval and update the timer
[self.configuration addObserver:self
Copy link
Contributor Author

@fathyb fathyb Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured we might want to observe this using KVO instead of having cyclic references between Configuration and  Analytics. Let me know if you think this is overkill.

@fathyb fathyb force-pushed the feat/configure-flush-interval branch from f6901b4 to c6c763b Compare July 13, 2018 14:29
Copy link
Contributor

@f2prateek f2prateek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is a bit bigger than I expected. I think we should narrow it down a bit more, and avoid changing too much logic without scoping out the impact in a bit more detail.

I was thinking all we need to change here would be not hardcode 30 here https://github.com/segmentio/analytics-ios/blob/master/Analytics/Classes/Internal/SEGSegmentIntegration.m#L122, and pull it from the configuration instead.

We can still do bigger changes if we need to but I think it should be a different PR/discussion. What do you think?

@fathyb fathyb force-pushed the feat/configure-flush-interval branch from 9197f06 to fcc084b Compare July 13, 2018 18:14
@fathyb
Copy link
Contributor Author

fathyb commented Jul 13, 2018

@f2prateek you're right, I was a bit worried about that. I pushed a simpler version with no observers and no logic changes

/**
* The amount of time to wait before each tick of the flush timer. Smaller values will make events delivered in a more real-time manner and also use more battery. `30` by default.
*/
@property (nonatomic, assign) NSTimeInterval flushInterval;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can someone set this to less than < 0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think something too low (1ms) may also be problematic. We should just say something like "Don't set this below 10seconds".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Apple :

interval

The number of seconds between firings of the timer. If interval is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead.

I added this note :

A value smaller than 10 seconds will seriously degrade overall performance.

@@ -61,6 +61,10 @@ typedef NSMutableURLRequest *_Nonnull (^SEGRequestFactory)(NSURL *_Nonnull);
*/
@property (nonatomic, assign) NSUInteger flushAt;

/**
* The amount of time to wait before each tick of the flush timer. Smaller values will make events delivered in a more real-time manner and also use more battery. `30` by default.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30 seconds will be clearer than just 30 I think

Copy link
Contributor

@f2prateek f2prateek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of documentation improvements that can be made, but looks good to me otherwise!

@f2prateek f2prateek merged commit 1ee901d into master Jul 16, 2018
@f2prateek f2prateek deleted the feat/configure-flush-interval branch July 16, 2018 18:10
toanz pushed a commit to ejoy-jsc/analytics-ios that referenced this pull request Sep 18, 2018
* Add a `flushInterval` configuration option

Ref: LIB-443

* Improve property documentation
bharath2020 pushed a commit to bharath2020/analytics-ios that referenced this pull request Mar 22, 2019
* Add a `flushInterval` configuration option

Ref: LIB-443

* Improve property documentation
bharath2020 pushed a commit to bharath2020/analytics-ios that referenced this pull request Mar 22, 2019
* Add a `flushInterval` configuration option

Ref: LIB-443

* Improve property documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants