RelationalCapacityPanel.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <script setup lang="ts">
  2. import { computed, shallowRef } from 'vue';
  3. import service from '/@/utils/request';
  4. type ApiInteger = number | string;
  5. interface CapacityResult {
  6. sample: {
  7. estimate: {
  8. sourceRows: ApiInteger | null;
  9. sourceRowsBasis: 'sample' | 'catalog' | 'sample-floor' | 'unknown';
  10. sampleRows: number;
  11. sampleBatches: number;
  12. sampleRawBytes: ApiInteger;
  13. rawBytesPerRow: number | null;
  14. fullRawBytes: ApiInteger | null;
  15. fullSecondsLow: number | null;
  16. fullSecondsHigh: number | null;
  17. };
  18. isolatedRows: number;
  19. setupMs: number;
  20. sourceMs: number;
  21. rawMs: number;
  22. cleanMs: number;
  23. handoffMs: number;
  24. reconcileMs: number;
  25. };
  26. history: {
  27. increments: { recordedDays: number; dailyIncrementRows: number | null };
  28. full: { sourceRows: ApiInteger; pageCount: number; completedUtc: string; elapsedMs: number } | null;
  29. rawBytes?: ApiInteger | null;
  30. rawToCleanMs?: number | null;
  31. } | null;
  32. }
  33. const props = defineProps<{ endpoint: string; factoryId: string; active: boolean }>();
  34. const busy = shallowRef(false);
  35. const result = shallowRef<CapacityResult>();
  36. const retentionDays = shallowRef<number | undefined>(30);
  37. const dailyOverride = shallowRef<number>();
  38. const historicalDaily = computed(() => {
  39. const increments = result.value?.history?.increments;
  40. return increments && increments.recordedDays >= 2 ? increments.dailyIncrementRows : null;
  41. });
  42. const forecast = computed(() => {
  43. const estimate = result.value?.sample.estimate;
  44. const dailyRows = dailyOverride.value ?? historicalDaily.value;
  45. const days = retentionDays.value;
  46. if (!estimate?.sampleRows || dailyRows == null || !days) return null;
  47. const perRow = Number(estimate.sampleRawBytes) / estimate.sampleRows;
  48. const daily = Math.ceil(perRow * dailyRows);
  49. const incremental = Math.ceil(perRow * dailyRows * days);
  50. const total = estimate.fullRawBytes == null ? null : Number(estimate.fullRawBytes) + incremental;
  51. return { daily, incremental, total };
  52. });
  53. const number = new Intl.NumberFormat('zh-CN', { maximumFractionDigits: 3 });
  54. const amount = (value: ApiInteger | null | undefined) => value == null ? '待估算' : number.format(Number(value));
  55. const bytes = (value: ApiInteger | null | undefined) => {
  56. if (value == null) return '待估算';
  57. const units = ['字节', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
  58. let size = Number(value);
  59. let index = 0;
  60. while (size >= 1024 && index < units.length - 1) {
  61. size /= 1024;
  62. index++;
  63. }
  64. return `${number.format(size)} ${units[index]}`;
  65. };
  66. const elapsed = (value: number | null | undefined) => value == null ? '未记录' : `${number.format(value)} 毫秒`;
  67. const rowCountBasis = {
  68. sample: '本次已读到来源末尾,采用本次读取行数',
  69. catalog: '行数采用源目录统计',
  70. 'sample-floor': '源目录低于已读行数,当前以样本行数为估算下限',
  71. unknown: '源目录没有行数统计',
  72. };
  73. const forecastTime = computed(() => {
  74. const estimate = result.value?.sample.estimate;
  75. const low = estimate?.fullSecondsLow;
  76. const high = estimate?.fullSecondsHigh;
  77. if (low == null || high == null) return '待估算';
  78. return low === high ? `约 ${amount(low)} 秒` : `${amount(low)}–${amount(high)} 秒`;
  79. });
  80. async function measure() {
  81. if (!props.active || busy.value) return;
  82. busy.value = true;
  83. try {
  84. const response = await service.post<CapacityResult>(props.endpoint, {}, {
  85. params: { factoryId: props.factoryId },
  86. timeout: 40000,
  87. });
  88. result.value = response.data;
  89. } finally {
  90. busy.value = false;
  91. }
  92. }
  93. </script>
  94. <template>
  95. <section class="relational-capacity">
  96. <h4>同步耗时和保留容量</h4>
  97. <el-button :loading="busy" :disabled="!active" @click="measure">运行隔离测算</el-button>
  98. <p v-if="!active">启用已审批的来源版本后可以运行测算。</p>
  99. <div v-if="result" role="status">
  100. <p>样本 {{ result.sample.estimate.sampleRows }} 行 · {{ result.sample.estimate.sampleBatches }} 批 · Raw {{ bytes(result.sample.estimate.sampleRawBytes) }} · 隔离 {{ result.sample.isolatedRows }} 行</p>
  101. <p v-if="!result.sample.estimate.sampleRows">来源没有可用样本,耗时及每行容量待估算。</p>
  102. <p v-else-if="result.sample.estimate.sourceRows == null">源目录没有行数统计,首次全量待估算。</p>
  103. <p v-if="result.sample.isolatedRows">样本出现隔离。请复核来源字段和映射,再用于投产评估。</p>
  104. <template v-if="result.sample.estimate.sampleRows">
  105. <p>沙箱准备 {{ elapsed(result.sample.setupMs) }} · 源库读取 {{ elapsed(result.sample.sourceMs) }} · Raw 入库 {{ elapsed(result.sample.rawMs) }}</p>
  106. <p>清洗 {{ elapsed(result.sample.cleanMs) }} · 贴源及标准层 {{ elapsed(result.sample.handoffMs) }} · 对账 {{ elapsed(result.sample.reconcileMs) }}</p>
  107. </template>
  108. <p>首次全量预计 {{ amount(result.sample.estimate.sourceRows) }} 行 · {{ forecastTime }} · Raw {{ bytes(result.sample.estimate.fullRawBytes) }}</p>
  109. <p v-if="result.sample.estimate.sampleRows">{{ rowCountBasis[result.sample.estimate.sourceRowsBasis] }}。每行 Raw {{ bytes(result.sample.estimate.rawBytesPerRow) }},耗时按样本批次速度推算。队列等待见实际运行。</p>
  110. <div class="capacity-inputs">
  111. <label>保留天数 <el-input-number v-model="retentionDays" :min="1" :max="3650" :precision="0" aria-label="保留天数" /></label>
  112. <label>日均增量假设 <el-input-number v-model="dailyOverride" :min="0" :max="1000000000" :precision="0" placeholder="沿用历史" aria-label="日均增量假设" /></label>
  113. </div>
  114. <p v-if="dailyOverride != null">使用手填假设,每日 {{ amount(dailyOverride) }} 行。</p>
  115. <p v-else-if="historicalDaily != null">取近 14 天内 {{ result.history?.increments.recordedDays }} 个有对账记录的完整 UTC 日,日均 {{ amount(historicalDaily) }} 行,含增量窗口的重叠数据。</p>
  116. <p v-else>日均增量待估算。历史记录不足时可填写假设值。</p>
  117. <p>每日 Raw {{ bytes(forecast?.daily) }} · 保留期增量 Raw {{ bytes(forecast?.incremental) }} · 含首次全量 {{ bytes(forecast?.total) }}</p>
  118. <p>容量按 Raw 原文计算,索引及贴源、标准层各自占用空间。</p>
  119. <template v-if="result.history?.full">
  120. <p>最近一次已对账全量 {{ result.history.full.sourceRows }} 行 · {{ result.history.full.pageCount }} 批 · Raw {{ bytes(result.history.rawBytes) }}</p>
  121. <p>实际全程 {{ elapsed(result.history.full.elapsedMs) }},含排队和对账等待。每批 Raw 入库至清洗完成平均 {{ elapsed(result.history.rawToCleanMs) }},含 Worker 排队。</p>
  122. </template>
  123. <p v-else>当前配置暂无已对账全量可供比较。</p>
  124. </div>
  125. </section>
  126. </template>
  127. <style scoped>
  128. .relational-capacity { margin: 14px 0; }
  129. .capacity-inputs { display: flex; flex-wrap: wrap; gap: 12px 20px; }
  130. .capacity-inputs label { display: inline-flex; align-items: center; gap: 8px; }
  131. </style>