pubsub: fix ack message size

use subscription name to calculate msg size
remove unused constant in service.go

Fixes #1441

Change-Id: I03dd06e8ddb5ce76b9adbc306026d9d563587357
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/41710
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alex Hong <hongalex@google.com>
diff --git a/pubsub/iterator.go b/pubsub/iterator.go
index 7cffa25..521726e 100644
--- a/pubsub/iterator.go
+++ b/pubsub/iterator.go
@@ -443,7 +443,7 @@
 	}
 	var toSend []string
 	for len(ackIDs) > 0 {
-		toSend, ackIDs = splitRequestIDs(ackIDs, maxPayload)
+		toSend, ackIDs = splitRequestIDs(ackIDs, len(it.subName), maxPayload)
 		if err := call(toSend); err != nil {
 			// The underlying client handles retries, so any error is fatal to the
 			// iterator.
@@ -465,8 +465,8 @@
 	_ = it.ps.Send(&pb.StreamingPullRequest{})
 }
 
-func splitRequestIDs(ids []string, maxSize int) (prefix, remainder []string) {
-	size := reqFixedOverhead
+func splitRequestIDs(ids []string, overHeadLength, maxSize int) (prefix, remainder []string) {
+	size := overHeadLength
 	i := 0
 	for size < maxSize && i < len(ids) {
 		size += overheadPerID + len(ids[i])
diff --git a/pubsub/iterator_test.go b/pubsub/iterator_test.go
index 6ed4fb6..0e2aa60 100644
--- a/pubsub/iterator_test.go
+++ b/pubsub/iterator_test.go
@@ -41,6 +41,7 @@
 func TestSplitRequestIDs(t *testing.T) {
 	t.Parallel()
 	ids := []string{"aaaa", "bbbb", "cccc", "dddd", "eeee"}
+	subName := "s"
 	for _, test := range []struct {
 		ids        []string
 		splitIndex int
@@ -49,7 +50,7 @@
 		{ids, 2},
 		{ids[:2], 2},
 	} {
-		got1, got2 := splitRequestIDs(test.ids, reqFixedOverhead+20)
+		got1, got2 := splitRequestIDs(test.ids, len(subName), 15)
 		want1, want2 := test.ids[:test.splitIndex], test.ids[test.splitIndex:]
 		if !testutil.Equal(got1, want1) {
 			t.Errorf("%v, 1: got %v, want %v", test, got1, want1)
diff --git a/pubsub/service.go b/pubsub/service.go
index b7358fe..84168ae 100644
--- a/pubsub/service.go
+++ b/pubsub/service.go
@@ -39,8 +39,7 @@
 // it 512K.
 const (
 	maxPayload       = 512 * 1024
-	reqFixedOverhead = 100
-	overheadPerID    = 3
+	overheadPerID    = 3                //3 bytes per ID (a tag byte and two size bytes)
 	maxSendRecvBytes = 20 * 1024 * 1024 // 20M
 )