pingcap / go-tpc

A toolbox to benchmark TPC workloads in Go
Apache License 2.0
178 stars 94 forks source link

something not very well under multi threads #183

Open starxchina opened 1 month ago

starxchina commented 1 month ago
func (m *Measurement) getHist(op string, err error, current bool) *Histogram {
    opMeasurement := m.OpSumMeasurement
    if current {
        opMeasurement = m.OpCurMeasurement
    }

    // Create hist of {op} and {op}_ERR at the same time, or else the TPM would be incorrect
    opPairedKey := fmt.Sprintf("%s_ERR", op)
    if err != nil {
        op, opPairedKey = opPairedKey, op
    }

    m.RLock()
    opM, ok := opMeasurement[op]
    m.RUnlock()
    if !ok {
        opM = NewHistogram(m.MinLatency, m.MaxLatency, m.SigFigs)
        opPairedM := NewHistogram(m.MinLatency, m.MaxLatency, m.SigFigs)
        m.Lock()
        opMeasurement[op] = opM
        opMeasurement[opPairedKey] = opPairedM
        m.Unlock()
    }
    return opM
}

there will exist data loss under multi threads in pkg/measurement/measure.go: if !ok {...}