@@ -47,6 +47,8 @@ DEFINE_string(benchmarks,
47
47
" overwrite,"
48
48
" readrandom,"
49
49
" readrandom,"
50
+ " newiterator,"
51
+ " newiteratorwhilewriting,"
50
52
" readseq,"
51
53
" readreverse,"
52
54
" compact,"
@@ -1172,6 +1174,9 @@ class Benchmark {
1172
1174
method = &Benchmark::ReadRandom;
1173
1175
} else if (name == Slice (" newiterator" )) {
1174
1176
method = &Benchmark::IteratorCreation;
1177
+ } else if (name == Slice (" newiteratorwhilewriting" )) {
1178
+ num_threads++; // Add extra thread for writing
1179
+ method = &Benchmark::IteratorCreationWhileWriting;
1175
1180
} else if (name == Slice (" seekrandom" )) {
1176
1181
method = &Benchmark::SeekRandom;
1177
1182
} else if (name == Slice (" readrandomsmall" )) {
@@ -1864,13 +1869,22 @@ class Benchmark {
1864
1869
void IteratorCreation (ThreadState* thread) {
1865
1870
Duration duration (FLAGS_duration, reads_);
1866
1871
ReadOptions options (FLAGS_verify_checksum, true );
1872
+ options.prefix_seek = (FLAGS_prefix_size > 0 );
1867
1873
while (!duration.Done (1 )) {
1868
1874
Iterator* iter = db_->NewIterator (options);
1869
1875
delete iter;
1870
1876
thread->stats .FinishedSingleOp (db_);
1871
1877
}
1872
1878
}
1873
1879
1880
+ void IteratorCreationWhileWriting (ThreadState* thread) {
1881
+ if (thread->tid > 0 ) {
1882
+ IteratorCreation (thread);
1883
+ } else {
1884
+ BGWriter (thread);
1885
+ }
1886
+ }
1887
+
1874
1888
void SeekRandom (ThreadState* thread) {
1875
1889
int64_t read = 0 ;
1876
1890
int64_t found = 0 ;
@@ -1934,53 +1948,57 @@ class Benchmark {
1934
1948
if (thread->tid > 0 ) {
1935
1949
ReadRandom (thread);
1936
1950
} else {
1937
- // Special thread that keeps writing until other threads are done.
1938
- RandomGenerator gen;
1939
- double last = FLAGS_env->NowMicros ();
1940
- int writes_per_second_by_10 = 0 ;
1941
- int num_writes = 0 ;
1942
-
1943
- // --writes_per_second rate limit is enforced per 100 milliseconds
1944
- // intervals to avoid a burst of writes at the start of each second.
1945
-
1946
- if (FLAGS_writes_per_second > 0 )
1947
- writes_per_second_by_10 = FLAGS_writes_per_second / 10 ;
1948
-
1949
- // Don't merge stats from this thread with the readers.
1950
- thread->stats .SetExcludeFromMerge ();
1951
-
1952
- Slice key = AllocateKey ();
1953
- std::unique_ptr<const char []> key_guard (key.data ());
1954
-
1955
- while (true ) {
1956
- {
1957
- MutexLock l (&thread->shared ->mu );
1958
- if (thread->shared ->num_done + 1 >= thread->shared ->num_initialized ) {
1959
- // Other threads have finished
1960
- break ;
1961
- }
1962
- }
1951
+ BGWriter (thread);
1952
+ }
1953
+ }
1963
1954
1964
- GenerateKeyFromInt (thread->rand .Next () % FLAGS_num, FLAGS_num, &key);
1965
- Status s = db_->Put (write_options_, key, gen.Generate (value_size_));
1966
- if (!s.ok ()) {
1967
- fprintf (stderr, " put error: %s\n " , s.ToString ().c_str ());
1968
- exit (1 );
1955
+ void BGWriter (ThreadState* thread) {
1956
+ // Special thread that keeps writing until other threads are done.
1957
+ RandomGenerator gen;
1958
+ double last = FLAGS_env->NowMicros ();
1959
+ int writes_per_second_by_10 = 0 ;
1960
+ int num_writes = 0 ;
1961
+
1962
+ // --writes_per_second rate limit is enforced per 100 milliseconds
1963
+ // intervals to avoid a burst of writes at the start of each second.
1964
+
1965
+ if (FLAGS_writes_per_second > 0 )
1966
+ writes_per_second_by_10 = FLAGS_writes_per_second / 10 ;
1967
+
1968
+ // Don't merge stats from this thread with the readers.
1969
+ thread->stats .SetExcludeFromMerge ();
1970
+
1971
+ Slice key = AllocateKey ();
1972
+ std::unique_ptr<const char []> key_guard (key.data ());
1973
+
1974
+ while (true ) {
1975
+ {
1976
+ MutexLock l (&thread->shared ->mu );
1977
+ if (thread->shared ->num_done + 1 >= thread->shared ->num_initialized ) {
1978
+ // Other threads have finished
1979
+ break ;
1969
1980
}
1970
- thread->stats .FinishedSingleOp (db_);
1981
+ }
1982
+
1983
+ GenerateKeyFromInt (thread->rand .Next () % FLAGS_num, FLAGS_num, &key);
1984
+ Status s = db_->Put (write_options_, key, gen.Generate (value_size_));
1985
+ if (!s.ok ()) {
1986
+ fprintf (stderr, " put error: %s\n " , s.ToString ().c_str ());
1987
+ exit (1 );
1988
+ }
1989
+ thread->stats .FinishedSingleOp (db_);
1971
1990
1972
- ++num_writes;
1973
- if (writes_per_second_by_10 && num_writes >= writes_per_second_by_10) {
1974
- double now = FLAGS_env->NowMicros ();
1975
- double usecs_since_last = now - last;
1991
+ ++num_writes;
1992
+ if (writes_per_second_by_10 && num_writes >= writes_per_second_by_10) {
1993
+ double now = FLAGS_env->NowMicros ();
1994
+ double usecs_since_last = now - last;
1976
1995
1977
- num_writes = 0 ;
1978
- last = now;
1996
+ num_writes = 0 ;
1997
+ last = now;
1979
1998
1980
- if (usecs_since_last < 100000.0 ) {
1981
- FLAGS_env->SleepForMicroseconds (100000.0 - usecs_since_last);
1982
- last = FLAGS_env->NowMicros ();
1983
- }
1999
+ if (usecs_since_last < 100000.0 ) {
2000
+ FLAGS_env->SleepForMicroseconds (100000.0 - usecs_since_last);
2001
+ last = FLAGS_env->NowMicros ();
1984
2002
}
1985
2003
}
1986
2004
}
0 commit comments