Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Send multiple notifications concurrently #54

Merged
merged 6 commits into from
Jun 10, 2016
Merged

Send multiple notifications concurrently #54

merged 6 commits into from
Jun 10, 2016

Conversation

nathany
Copy link
Contributor

@nathany nathany commented Jun 9, 2016

closes #31
closes #40

  • example of sending notifications concurrently
  • build a worker pool into Service
  • update README
  • review and revise API
  • tests for concurrent notifications

@nathany
Copy link
Contributor Author

nathany commented Jun 9, 2016

If we want this to be the default behaviour, what would that involve?

A Service could have a worker pool.
The main thing is that responses are concurrent, so we need a channel in the API?
Do we keep the existing synchronous APIs?
Do both Push and PushBytes adopt this?

@nathany
Copy link
Contributor Author

nathany commented Jun 9, 2016

ATM I'm thinking:

  • NewService sets up some workers and the channels
  • Push and PushBytes take the same params but just queue up a notification (no response)
  • A method to close the channel and shutdown the workers
  • Response() method blocks for a response and returns (id, *Notification, error)

if err != nil {
return nil, err
}
// notification to send.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

move this internal stuff down

@nathany
Copy link
Contributor Author

nathany commented Jun 9, 2016

Should push.notification be exported?

  • NewNotification that does marshalling and may return an error
  • PushNotification(n)
  • Include the whole Notification in Response(), not just deviceToken
  • []Notification could be useful for preparing notifications to send

Should pushSync be exported?

Should there be an internal WaitGroup that Shutdown() waits on to ensure all responses have been received?

Using x/net/http2 directly instead of ConfigureTransport could allow support for Go 1.5.x (if desired), and make it so NewClient() doesn't return an error.
https://github.com/sideshow/apns2/blob/master/client.go#L60

var workers uint
var number int

flag.StringVar(&deviceToken, "d", "", "Device token")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice good idea to add CLI control

@nathany
Copy link
Contributor Author

nathany commented Jun 10, 2016

TODO: write tests that exercise the concurrency (multiple notifications) for testing with the race detector.

Look at where pointers are used or not used and decide which is preferable.

Reconsider how Error responses from Apple are provided. Could make the type conversion to *push.Error unnecessary.

// wait group to wait for all responses
var wg sync.WaitGroup

// process responses
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's important that this is setup prior to sending notifications, otherwise there won't be room in the responses channel. Document this more thoroughly.

@curtisallen
Copy link
Contributor

Other then a nit pick LGTM 👍

@nathany
Copy link
Contributor Author

nathany commented Jun 10, 2016

I experimented with NewNotification but I'm not in love with it.

Also still considering supporting a synchronous push.

}

// NewClient sets up an HTTP/2 client for a certificate.
func newClient(cert tls.Certificate) (*http.Client, error) {
func NewClient(cert tls.Certificate) (*http.Client, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exposing NewClient again, as it was in v0.4.x

and improve handling of command line flags
log.Fatal(err)
// process responses
go func() {
for {
Copy link
Contributor Author

@nathany nathany Jun 10, 2016

Choose a reason for hiding this comment

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

There should probably be a signal to shutdown this goroutine. Hmm. #56

(not sure how useful this test is)
@nathany nathany merged commit 9ff2361 into master Jun 10, 2016
@nathany nathany deleted the concurrent branch June 10, 2016 20:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accessing push.Service concurrently? Slow sending 50000+ push
2 participants