change(tracker): only compress big batches, set mtime 0
This commit is contained in:
parent
312600ee56
commit
8fff087862
4 changed files with 22 additions and 6 deletions
|
|
@ -26,6 +26,7 @@ export type ToWorkerData =
|
|||
| Auth
|
||||
| Array<Message>
|
||||
| { type: 'compressed'; batch: Uint8Array }
|
||||
| { type: 'uncompressed'; batch: Uint8Array }
|
||||
|
||||
type Failure = {
|
||||
type: 'failure'
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ export default class App {
|
|||
private activityState: ActivityState = ActivityState.NotActive
|
||||
private readonly version = 'TRACKER_VERSION' // TODO: version compatability check inside each plugin.
|
||||
private readonly worker?: TypedWorker
|
||||
|
||||
constructor(projectKey: string, sessionToken: string | undefined, options: Partial<Options>) {
|
||||
// if (options.onStart !== undefined) {
|
||||
// deprecationWarn("'onStart' option", "tracker.start().then(/* handle session info */)")
|
||||
|
|
@ -179,10 +180,17 @@ export default class App {
|
|||
this.stop(false)
|
||||
this._debug('worker_failed', data.reason)
|
||||
} else if (data.type === 'compress') {
|
||||
gzip(data.batch, (err, result) => {
|
||||
if (err) console.error(err)
|
||||
this.worker?.postMessage({ type: 'compressed', batch: result })
|
||||
})
|
||||
const batch = data.batch
|
||||
const batchSize = batch.byteLength
|
||||
console.log(batchSize)
|
||||
if (batchSize > 1000 * 10) {
|
||||
gzip(data.batch, { mtime: 0 }, (err, result) => {
|
||||
if (err) console.error(err)
|
||||
this.worker?.postMessage({ type: 'compressed', batch: result })
|
||||
})
|
||||
} else {
|
||||
this.worker?.postMessage({ type: 'uncompressed', batch: batch })
|
||||
}
|
||||
}
|
||||
}
|
||||
const alertWorker = () => {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ export default class QueueSender {
|
|||
}
|
||||
|
||||
// would be nice to use Beacon API, but it is not available in WebWorker
|
||||
private sendBatch(batch: Uint8Array): void {
|
||||
private sendBatch(batch: Uint8Array, isCompressed?: boolean): void {
|
||||
this.busy = true
|
||||
|
||||
// @ts-ignore
|
||||
|
|
@ -66,7 +66,7 @@ export default class QueueSender {
|
|||
headers: {
|
||||
Authorization: `Bearer ${this.token as string}`,
|
||||
//"Content-Type": "",
|
||||
'Content-Encoding': 'gzip',
|
||||
// 'Content-Encoding': isCompressed ? 'gzip' : undefined,
|
||||
},
|
||||
keepalive: batch.length < KEEPALIVE_SIZE_LIMIT,
|
||||
})
|
||||
|
|
@ -92,6 +92,10 @@ export default class QueueSender {
|
|||
}
|
||||
|
||||
sendCompressed(batch: Uint8Array) {
|
||||
this.sendBatch(batch, true)
|
||||
}
|
||||
|
||||
sendUncompressed(batch: Uint8Array) {
|
||||
this.sendBatch(batch)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -134,6 +134,9 @@ self.onmessage = ({ data }: any): any => {
|
|||
if (data.type === 'compressed') {
|
||||
sender?.sendCompressed(data.batch)
|
||||
}
|
||||
if (data.type === 'uncompressed') {
|
||||
sender?.sendUncompressed(data.batch)
|
||||
}
|
||||
|
||||
if (data.type === 'auth') {
|
||||
if (!sender) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue