Skip to content

Commit

Permalink
feat: 优化系统GC采样效率 TencentBlueKing#1600 (TencentBlueKing#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixncheng authored Jan 8, 2024
1 parent 47e22c1 commit 2702b08
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tencent.bkrepo.archive.api

import com.tencent.bkrepo.archive.pojo.ArchiveFile
import com.tencent.bkrepo.archive.pojo.CompressFile
import com.tencent.bkrepo.archive.request.ArchiveFileRequest
import com.tencent.bkrepo.archive.request.CompleteCompressRequest
import com.tencent.bkrepo.archive.request.CompressFileRequest
Expand Down Expand Up @@ -43,7 +44,7 @@ interface ArchiveClient {
): Response<ArchiveFile?>

@PutMapping("/compress")
fun compress(@RequestBody request: CompressFileRequest): Response<Void>
fun compress(@RequestBody request: CompressFileRequest): Response<Int>

@PutMapping("/uncompress")
fun uncompress(@RequestBody request: UncompressFileRequest): Response<Void>
Expand All @@ -54,6 +55,12 @@ interface ArchiveClient {
@PutMapping("/compress/complete")
fun completeCompress(@RequestBody request: CompleteCompressRequest): Response<Void>

@GetMapping("/compress")
fun getCompressInfo(
@RequestParam sha256: String,
@RequestParam(required = false) storageCredentialsKey: String?,
): Response<CompressFile?>

@DeleteMapping("/deleteAll")
fun deleteAll(@RequestBody request: ArchiveFileRequest): Response<Void>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.tencent.bkrepo.archive.ArchiveStatus
import java.time.LocalDateTime

data class ArchiveFile(
var id: String? = null,
var createdBy: String,
var createdDate: LocalDateTime,
var lastModifiedBy: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.tencent.bkrepo.archive.pojo

import com.tencent.bkrepo.archive.CompressStatus
import java.time.LocalDateTime

data class CompressFile(
var createdBy: String,
var createdDate: LocalDateTime,
var lastModifiedBy: String,
var lastModifiedDate: LocalDateTime,
val sha256: String,
val baseSha256: String,
val uncompressedSize: Long,
var compressedSize: Long = -1,
val storageCredentialsKey: String?,
var status: CompressStatus,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.tencent.bkrepo.archive.controller.service

import com.tencent.bkrepo.archive.api.ArchiveClient
import com.tencent.bkrepo.archive.pojo.ArchiveFile
import com.tencent.bkrepo.archive.pojo.CompressFile
import com.tencent.bkrepo.archive.request.ArchiveFileRequest
import com.tencent.bkrepo.archive.request.CompleteCompressRequest
import com.tencent.bkrepo.archive.request.CompressFileRequest
Expand Down Expand Up @@ -46,9 +47,8 @@ class ArchiveController(
return ResponseBuilder.success()
}

override fun compress(request: CompressFileRequest): Response<Void> {
compressService.compress(request)
return ResponseBuilder.success()
override fun compress(request: CompressFileRequest): Response<Int> {
return ResponseBuilder.success(compressService.compress(request))
}

override fun uncompress(request: UncompressFileRequest): Response<Void> {
Expand All @@ -66,6 +66,10 @@ class ArchiveController(
return ResponseBuilder.success()
}

override fun getCompressInfo(sha256: String, storageCredentialsKey: String?): Response<CompressFile?> {
return ResponseBuilder.success(compressService.getCompressInfo(sha256, storageCredentialsKey))
}

override fun deleteAll(request: ArchiveFileRequest): Response<Void> {
archiveService.delete(request)
val deleteCompressRequest = DeleteCompressRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class ArchiveServiceImpl(
val af = archiveFileRepository.findBySha256AndStorageCredentialsKey(sha256, storageCredentialsKey)
?: return null
return ArchiveFile(
id = af.id,
createdBy = af.createdBy,
createdDate = af.createdDate,
lastModifiedBy = af.lastModifiedBy,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tencent.bkrepo.archive.service

import com.tencent.bkrepo.archive.pojo.CompressFile
import com.tencent.bkrepo.archive.request.CompleteCompressRequest
import com.tencent.bkrepo.archive.request.CompressFileRequest
import com.tencent.bkrepo.archive.request.DeleteCompressRequest
Expand All @@ -11,8 +12,9 @@ import com.tencent.bkrepo.archive.request.UncompressFileRequest
interface CompressService {
/**
* 压缩文件
* @return 1表示压缩成功,0表示未压缩
* */
fun compress(request: CompressFileRequest)
fun compress(request: CompressFileRequest): Int

/**
* 解压文件
Expand All @@ -30,4 +32,12 @@ interface CompressService {
* 完成压缩
* */
fun complete(request: CompleteCompressRequest)

/**
* 获取压缩信息
* */
fun getCompressInfo(
sha256: String,
storageCredentialsKey: String?,
): CompressFile?
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.tencent.bkrepo.archive.CompressStatus
import com.tencent.bkrepo.archive.job.compress.CompressSubscriber
import com.tencent.bkrepo.archive.job.compress.UncompressSubscriber
import com.tencent.bkrepo.archive.model.TCompressFile
import com.tencent.bkrepo.archive.pojo.CompressFile
import com.tencent.bkrepo.archive.repository.CompressFileDao
import com.tencent.bkrepo.archive.repository.CompressFileRepository
import com.tencent.bkrepo.archive.request.CompleteCompressRequest
Expand Down Expand Up @@ -47,7 +48,7 @@ class CompressServiceImpl(
executor,
)

override fun compress(request: CompressFileRequest) {
override fun compress(request: CompressFileRequest): Int {
with(request) {
// 队头元素
val head = compressFileRepository.findBySha256AndStorageCredentialsKey(sha256, storageCredentialsKey)
Expand All @@ -61,7 +62,7 @@ class CompressServiceImpl(
head.status = CompressStatus.COMPRESSED
compressFileRepository.save(head)
}
return
return 1
}
var currentChainLength = 0
// 这是队头
Expand All @@ -71,7 +72,7 @@ class CompressServiceImpl(
if (currentChainLength > MAX_CHAIN_LENGTH) {
// 超出队列长度
logger.info("Exceed max chain length,ignore it.")
return
return 0
}
// 删除旧头
compressFileRepository.delete(head)
Expand Down Expand Up @@ -116,6 +117,7 @@ class CompressServiceImpl(
if (sync) {
compressor.doOnNext(compressFile)
}
return 1
}
}

Expand Down Expand Up @@ -174,6 +176,27 @@ class CompressServiceImpl(
}
}

override fun getCompressInfo(sha256: String, storageCredentialsKey: String?): CompressFile? {
val file = compressFileRepository.findBySha256AndStorageCredentialsKey(sha256, storageCredentialsKey)
if (file == null || file.status == CompressStatus.NONE) {
return null
}
with(file) {
return CompressFile(
createdBy = createdBy,
createdDate = createdDate,
lastModifiedBy = lastModifiedBy,
lastModifiedDate = lastModifiedDate,
sha256 = sha256,
baseSha256 = baseSha256,
status = status,
compressedSize = compressedSize,
uncompressedSize = uncompressedSize,
storageCredentialsKey = storageCredentialsKey,
)
}
}

companion object {
private val logger = LoggerFactory.getLogger(CompressServiceImpl::class.java)
private const val MAX_CHAIN_LENGTH = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ fun <E> Collection<E>.groupBySimilar(key: (x1: E) -> String, similar: (x1: E, x2
* 2. 中间存在干扰数据,加入之前的组
* 3. 新建一个组
* */
if (similar(group.last(), str2)) {
// 判断新加入的元素与一头一尾是否相似,控制单个分类不要过于离散
if (similar(group.first(), str2) && similar(group.last(), str2)) {
group.add(str2)
} else if (previousGroup != null && similar(previousGroup.last(), str2)) {
} else if (previousGroup != null && similar(group.first(), str2) && similar(previousGroup.last(), str2)) {
previousGroup.add(str2)
} else {
if (group.size > 1) {
Expand Down
Loading

0 comments on commit 2702b08

Please sign in to comment.