| 827 | } |
| 828 | |
| 829 | func busyWriteTx( |
| 830 | b *testing.B, |
| 831 | wg *sync.WaitGroup, sc <-chan struct{}, |
| 832 | st xi.Storage, kg keygen, e string, src [][]interface{}, |
| 833 | ) { |
| 834 | defer wg.Done() |
| 835 | var ( |
| 836 | tx *sql.Tx |
| 837 | err error |
| 838 | ) |
| 839 | for i := 0; ; i++ { |
| 840 | // Begin |
| 841 | if i%benchmarkQueriesPerTx == 0 { |
| 842 | if tx, err = st.Writer().Begin(); err != nil { |
| 843 | b.Errorf("failed to begin transaction: %v", err) |
| 844 | } |
| 845 | } |
| 846 | // Exec |
| 847 | select { |
| 848 | case <-sc: |
| 849 | // Also commit on exiting |
| 850 | if tx != nil { |
| 851 | if err = tx.Commit(); err != nil { |
| 852 | b.Errorf("failed to commit transaction: %v", err) |
| 853 | } |
| 854 | tx = nil |
| 855 | } |
| 856 | return |
| 857 | default: |
| 858 | // Exec |
| 859 | if _, err = tx.Exec(e, src[kg.next()]...); err != nil { |
| 860 | b.Errorf("failed to execute: %v", err) |
| 861 | } |
| 862 | } |
| 863 | // Commit |
| 864 | if (i+1)%benchmarkQueriesPerTx == 0 { |
| 865 | if err = tx.Commit(); err != nil { |
| 866 | b.Errorf("failed to commit transaction: %v", err) |
| 867 | } |
| 868 | tx = nil |
| 869 | } |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | func idleWriteTx( |
| 874 | b *testing.B, |