作者: 谢瑞阳 10225101483 徐翔宇 10225101535
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

683 řádky
20 KiB

  1. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. #include <sys/types.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "db/db_impl.h"
  8. #include "db/version_set.h"
  9. #include "leveldb/cache.h"
  10. #include "leveldb/db.h"
  11. #include "leveldb/env.h"
  12. #include "leveldb/write_batch.h"
  13. #include "port/port.h"
  14. #include "util/crc32c.h"
  15. #include "util/histogram.h"
  16. #include "util/random.h"
  17. #include "util/testutil.h"
  18. // Comma-separated list of operations to run in the specified order
  19. // Actual benchmarks:
  20. // fillseq -- write N values in sequential key order in async mode
  21. // fillrandom -- write N values in random key order in async mode
  22. // overwrite -- overwrite N values in random key order in async mode
  23. // fillsync -- write N/100 values in random key order in sync mode
  24. // fill100K -- write N/1000 100K values in random order in async mode
  25. // readseq -- read N times sequentially
  26. // readreverse -- read N times in reverse order
  27. // readrandom -- read N times in random order
  28. // readhot -- read N times in random order from 1% section of DB
  29. // crc32c -- repeated crc32c of 4K of data
  30. // acquireload -- load N*1000 times
  31. // Meta operations:
  32. // compact -- Compact the entire DB
  33. // stats -- Print DB stats
  34. // heapprofile -- Dump a heap profile (if supported by this port)
  35. static const char* FLAGS_benchmarks =
  36. "fillseq,"
  37. "fillsync,"
  38. "fillrandom,"
  39. "overwrite,"
  40. "readrandom,"
  41. "readrandom," // Extra run to allow previous compactions to quiesce
  42. "readseq,"
  43. "readreverse,"
  44. "compact,"
  45. "readrandom,"
  46. "readseq,"
  47. "readreverse,"
  48. "fill100K,"
  49. "crc32c,"
  50. "snappycomp,"
  51. "snappyuncomp,"
  52. "acquireload,"
  53. ;
  54. // Number of key/values to place in database
  55. static int FLAGS_num = 1000000;
  56. // Number of read operations to do. If negative, do FLAGS_num reads.
  57. static int FLAGS_reads = -1;
  58. // Size of each value
  59. static int FLAGS_value_size = 100;
  60. // Arrange to generate values that shrink to this fraction of
  61. // their original size after compression
  62. static double FLAGS_compression_ratio = 0.5;
  63. // Print histogram of operation timings
  64. static bool FLAGS_histogram = false;
  65. // Number of bytes to buffer in memtable before compacting
  66. // (initialized to default value by "main")
  67. static int FLAGS_write_buffer_size = 0;
  68. // Number of bytes to use as a cache of uncompressed data.
  69. // Negative means use default settings.
  70. static int FLAGS_cache_size = -1;
  71. // Maximum number of files to keep open at the same time (use default if == 0)
  72. static int FLAGS_open_files = 0;
  73. // If true, do not destroy the existing database. If you set this
  74. // flag and also specify a benchmark that wants a fresh database, that
  75. // benchmark will fail.
  76. static bool FLAGS_use_existing_db = false;
  77. // Use the db with the following name.
  78. static const char* FLAGS_db = "/tmp/dbbench";
  79. namespace leveldb {
  80. // Helper for quickly generating random data.
  81. namespace {
  82. class RandomGenerator {
  83. private:
  84. std::string data_;
  85. int pos_;
  86. public:
  87. RandomGenerator() {
  88. // We use a limited amount of data over and over again and ensure
  89. // that it is larger than the compression window (32KB), and also
  90. // large enough to serve all typical value sizes we want to write.
  91. Random rnd(301);
  92. std::string piece;
  93. while (data_.size() < 1048576) {
  94. // Add a short fragment that is as compressible as specified
  95. // by FLAGS_compression_ratio.
  96. test::CompressibleString(&rnd, FLAGS_compression_ratio, 100, &piece);
  97. data_.append(piece);
  98. }
  99. pos_ = 0;
  100. }
  101. Slice Generate(int len) {
  102. if (pos_ + len > data_.size()) {
  103. pos_ = 0;
  104. assert(len < data_.size());
  105. }
  106. pos_ += len;
  107. return Slice(data_.data() + pos_ - len, len);
  108. }
  109. };
  110. static Slice TrimSpace(Slice s) {
  111. int start = 0;
  112. while (start < s.size() && isspace(s[start])) {
  113. start++;
  114. }
  115. int limit = s.size();
  116. while (limit > start && isspace(s[limit-1])) {
  117. limit--;
  118. }
  119. return Slice(s.data() + start, limit - start);
  120. }
  121. }
  122. class Benchmark {
  123. private:
  124. Cache* cache_;
  125. DB* db_;
  126. int num_;
  127. int reads_;
  128. int heap_counter_;
  129. double start_;
  130. double last_op_finish_;
  131. int64_t bytes_;
  132. std::string message_;
  133. std::string post_message_;
  134. Histogram hist_;
  135. RandomGenerator gen_;
  136. Random rand_;
  137. // State kept for progress messages
  138. int done_;
  139. int next_report_; // When to report next
  140. void PrintHeader() {
  141. const int kKeySize = 16;
  142. PrintEnvironment();
  143. fprintf(stdout, "Keys: %d bytes each\n", kKeySize);
  144. fprintf(stdout, "Values: %d bytes each (%d bytes after compression)\n",
  145. FLAGS_value_size,
  146. static_cast<int>(FLAGS_value_size * FLAGS_compression_ratio + 0.5));
  147. fprintf(stdout, "Entries: %d\n", num_);
  148. fprintf(stdout, "RawSize: %.1f MB (estimated)\n",
  149. ((static_cast<int64_t>(kKeySize + FLAGS_value_size) * num_)
  150. / 1048576.0));
  151. fprintf(stdout, "FileSize: %.1f MB (estimated)\n",
  152. (((kKeySize + FLAGS_value_size * FLAGS_compression_ratio) * num_)
  153. / 1048576.0));
  154. PrintWarnings();
  155. fprintf(stdout, "------------------------------------------------\n");
  156. }
  157. void PrintWarnings() {
  158. #if defined(__GNUC__) && !defined(__OPTIMIZE__)
  159. fprintf(stdout,
  160. "WARNING: Optimization is disabled: benchmarks unnecessarily slow\n"
  161. );
  162. #endif
  163. #ifndef NDEBUG
  164. fprintf(stdout,
  165. "WARNING: Assertions are enabled; benchmarks unnecessarily slow\n");
  166. #endif
  167. // See if snappy is working by attempting to compress a compressible string
  168. const char text[] = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
  169. std::string compressed;
  170. if (!port::Snappy_Compress(text, sizeof(text), &compressed)) {
  171. fprintf(stdout, "WARNING: Snappy compression is not enabled\n");
  172. } else if (compressed.size() >= sizeof(text)) {
  173. fprintf(stdout, "WARNING: Snappy compression is not effective\n");
  174. }
  175. }
  176. void PrintEnvironment() {
  177. fprintf(stderr, "LevelDB: version %d.%d\n",
  178. kMajorVersion, kMinorVersion);
  179. #if defined(__linux)
  180. time_t now = time(NULL);
  181. fprintf(stderr, "Date: %s", ctime(&now)); // ctime() adds newline
  182. FILE* cpuinfo = fopen("/proc/cpuinfo", "r");
  183. if (cpuinfo != NULL) {
  184. char line[1000];
  185. int num_cpus = 0;
  186. std::string cpu_type;
  187. std::string cache_size;
  188. while (fgets(line, sizeof(line), cpuinfo) != NULL) {
  189. const char* sep = strchr(line, ':');
  190. if (sep == NULL) {
  191. continue;
  192. }
  193. Slice key = TrimSpace(Slice(line, sep - 1 - line));
  194. Slice val = TrimSpace(Slice(sep + 1));
  195. if (key == "model name") {
  196. ++num_cpus;
  197. cpu_type = val.ToString();
  198. } else if (key == "cache size") {
  199. cache_size = val.ToString();
  200. }
  201. }
  202. fclose(cpuinfo);
  203. fprintf(stderr, "CPU: %d * %s\n", num_cpus, cpu_type.c_str());
  204. fprintf(stderr, "CPUCache: %s\n", cache_size.c_str());
  205. }
  206. #endif
  207. }
  208. void Start() {
  209. start_ = Env::Default()->NowMicros() * 1e-6;
  210. bytes_ = 0;
  211. message_.clear();
  212. last_op_finish_ = start_;
  213. hist_.Clear();
  214. done_ = 0;
  215. next_report_ = 100;
  216. }
  217. void FinishedSingleOp() {
  218. if (FLAGS_histogram) {
  219. double now = Env::Default()->NowMicros() * 1e-6;
  220. double micros = (now - last_op_finish_) * 1e6;
  221. hist_.Add(micros);
  222. if (micros > 20000) {
  223. fprintf(stderr, "long op: %.1f micros%30s\r", micros, "");
  224. fflush(stderr);
  225. }
  226. last_op_finish_ = now;
  227. }
  228. done_++;
  229. if (done_ >= next_report_) {
  230. if (next_report_ < 1000) next_report_ += 100;
  231. else if (next_report_ < 5000) next_report_ += 500;
  232. else if (next_report_ < 10000) next_report_ += 1000;
  233. else if (next_report_ < 50000) next_report_ += 5000;
  234. else if (next_report_ < 100000) next_report_ += 10000;
  235. else if (next_report_ < 500000) next_report_ += 50000;
  236. else next_report_ += 100000;
  237. fprintf(stderr, "... finished %d ops%30s\r", done_, "");
  238. fflush(stderr);
  239. }
  240. }
  241. void Stop(const Slice& name) {
  242. double finish = Env::Default()->NowMicros() * 1e-6;
  243. // Pretend at least one op was done in case we are running a benchmark
  244. // that does nto call FinishedSingleOp().
  245. if (done_ < 1) done_ = 1;
  246. if (bytes_ > 0) {
  247. char rate[100];
  248. snprintf(rate, sizeof(rate), "%6.1f MB/s",
  249. (bytes_ / 1048576.0) / (finish - start_));
  250. if (!message_.empty()) {
  251. message_ = std::string(rate) + " " + message_;
  252. } else {
  253. message_ = rate;
  254. }
  255. }
  256. fprintf(stdout, "%-12s : %11.3f micros/op;%s%s\n",
  257. name.ToString().c_str(),
  258. (finish - start_) * 1e6 / done_,
  259. (message_.empty() ? "" : " "),
  260. message_.c_str());
  261. if (FLAGS_histogram) {
  262. fprintf(stdout, "Microseconds per op:\n%s\n", hist_.ToString().c_str());
  263. }
  264. fflush(stdout);
  265. if (!post_message_.empty()) {
  266. fprintf(stdout, "\n%s\n", post_message_.c_str());
  267. post_message_.clear();
  268. }
  269. }
  270. public:
  271. enum Order {
  272. SEQUENTIAL,
  273. RANDOM
  274. };
  275. enum DBState {
  276. FRESH,
  277. EXISTING
  278. };
  279. Benchmark()
  280. : cache_(FLAGS_cache_size >= 0 ? NewLRUCache(FLAGS_cache_size) : NULL),
  281. db_(NULL),
  282. num_(FLAGS_num),
  283. reads_(FLAGS_reads < 0 ? FLAGS_num : FLAGS_reads),
  284. heap_counter_(0),
  285. bytes_(0),
  286. rand_(301) {
  287. std::vector<std::string> files;
  288. Env::Default()->GetChildren(FLAGS_db, &files);
  289. for (int i = 0; i < files.size(); i++) {
  290. if (Slice(files[i]).starts_with("heap-")) {
  291. Env::Default()->DeleteFile(std::string(FLAGS_db) + "/" + files[i]);
  292. }
  293. }
  294. if (!FLAGS_use_existing_db) {
  295. DestroyDB(FLAGS_db, Options());
  296. }
  297. }
  298. ~Benchmark() {
  299. delete db_;
  300. delete cache_;
  301. }
  302. void Run() {
  303. PrintHeader();
  304. Open();
  305. const char* benchmarks = FLAGS_benchmarks;
  306. while (benchmarks != NULL) {
  307. const char* sep = strchr(benchmarks, ',');
  308. Slice name;
  309. if (sep == NULL) {
  310. name = benchmarks;
  311. benchmarks = NULL;
  312. } else {
  313. name = Slice(benchmarks, sep - benchmarks);
  314. benchmarks = sep + 1;
  315. }
  316. Start();
  317. WriteOptions write_options;
  318. bool known = true;
  319. if (name == Slice("fillseq")) {
  320. Write(write_options, SEQUENTIAL, FRESH, num_, FLAGS_value_size, 1);
  321. } else if (name == Slice("fillbatch")) {
  322. Write(write_options, SEQUENTIAL, FRESH, num_, FLAGS_value_size, 1000);
  323. } else if (name == Slice("fillrandom")) {
  324. Write(write_options, RANDOM, FRESH, num_, FLAGS_value_size, 1);
  325. } else if (name == Slice("overwrite")) {
  326. Write(write_options, RANDOM, EXISTING, num_, FLAGS_value_size, 1);
  327. } else if (name == Slice("fillsync")) {
  328. write_options.sync = true;
  329. Write(write_options, RANDOM, FRESH, num_ / 1000, FLAGS_value_size, 1);
  330. } else if (name == Slice("fill100K")) {
  331. Write(write_options, RANDOM, FRESH, num_ / 1000, 100 * 1000, 1);
  332. } else if (name == Slice("readseq")) {
  333. ReadSequential();
  334. } else if (name == Slice("readreverse")) {
  335. ReadReverse();
  336. } else if (name == Slice("readrandom")) {
  337. ReadRandom();
  338. } else if (name == Slice("readhot")) {
  339. ReadHot();
  340. } else if (name == Slice("readrandomsmall")) {
  341. int n = reads_;
  342. reads_ /= 1000;
  343. ReadRandom();
  344. reads_ = n;
  345. } else if (name == Slice("compact")) {
  346. Compact();
  347. } else if (name == Slice("crc32c")) {
  348. Crc32c(4096, "(4K per op)");
  349. } else if (name == Slice("acquireload")) {
  350. AcquireLoad();
  351. } else if (name == Slice("snappycomp")) {
  352. SnappyCompress();
  353. } else if (name == Slice("snappyuncomp")) {
  354. SnappyUncompress();
  355. } else if (name == Slice("heapprofile")) {
  356. HeapProfile();
  357. } else if (name == Slice("stats")) {
  358. PrintStats();
  359. } else {
  360. known = false;
  361. if (name != Slice()) { // No error message for empty name
  362. fprintf(stderr, "unknown benchmark '%s'\n", name.ToString().c_str());
  363. }
  364. }
  365. if (known) {
  366. Stop(name);
  367. }
  368. }
  369. }
  370. private:
  371. void Crc32c(int size, const char* label) {
  372. // Checksum about 500MB of data total
  373. std::string data(size, 'x');
  374. int64_t bytes = 0;
  375. uint32_t crc = 0;
  376. while (bytes < 500 * 1048576) {
  377. crc = crc32c::Value(data.data(), size);
  378. FinishedSingleOp();
  379. bytes += size;
  380. }
  381. // Print so result is not dead
  382. fprintf(stderr, "... crc=0x%x\r", static_cast<unsigned int>(crc));
  383. bytes_ = bytes;
  384. message_ = label;
  385. }
  386. void AcquireLoad() {
  387. int dummy;
  388. port::AtomicPointer ap(&dummy);
  389. int count = 0;
  390. void *ptr = NULL;
  391. message_ = "(each op is 1000 loads)";
  392. while (count < 100000) {
  393. for (int i = 0; i < 1000; i++) {
  394. ptr = ap.Acquire_Load();
  395. }
  396. count++;
  397. FinishedSingleOp();
  398. }
  399. if (ptr == NULL) exit(1); // Disable unused variable warning.
  400. }
  401. void SnappyCompress() {
  402. Slice input = gen_.Generate(Options().block_size);
  403. int64_t bytes = 0;
  404. int64_t produced = 0;
  405. bool ok = true;
  406. std::string compressed;
  407. while (ok && bytes < 1024 * 1048576) { // Compress 1G
  408. ok = port::Snappy_Compress(input.data(), input.size(), &compressed);
  409. produced += compressed.size();
  410. bytes += input.size();
  411. FinishedSingleOp();
  412. }
  413. if (!ok) {
  414. message_ = "(snappy failure)";
  415. } else {
  416. char buf[100];
  417. snprintf(buf, sizeof(buf), "(output: %.1f%%)",
  418. (produced * 100.0) / bytes);
  419. message_ = buf;
  420. bytes_ = bytes;
  421. }
  422. }
  423. void SnappyUncompress() {
  424. Slice input = gen_.Generate(Options().block_size);
  425. std::string compressed;
  426. bool ok = port::Snappy_Compress(input.data(), input.size(), &compressed);
  427. int64_t bytes = 0;
  428. char* uncompressed = new char[input.size()];
  429. while (ok && bytes < 1024 * 1048576) { // Compress 1G
  430. ok = port::Snappy_Uncompress(compressed.data(), compressed.size(),
  431. uncompressed);
  432. bytes += input.size();
  433. FinishedSingleOp();
  434. }
  435. delete[] uncompressed;
  436. if (!ok) {
  437. message_ = "(snappy failure)";
  438. } else {
  439. bytes_ = bytes;
  440. }
  441. }
  442. void Open() {
  443. assert(db_ == NULL);
  444. Options options;
  445. options.create_if_missing = !FLAGS_use_existing_db;
  446. options.block_cache = cache_;
  447. options.write_buffer_size = FLAGS_write_buffer_size;
  448. Status s = DB::Open(options, FLAGS_db, &db_);
  449. if (!s.ok()) {
  450. fprintf(stderr, "open error: %s\n", s.ToString().c_str());
  451. exit(1);
  452. }
  453. }
  454. void Write(const WriteOptions& options, Order order, DBState state,
  455. int num_entries, int value_size, int entries_per_batch) {
  456. if (state == FRESH) {
  457. if (FLAGS_use_existing_db) {
  458. message_ = "skipping (--use_existing_db is true)";
  459. return;
  460. }
  461. delete db_;
  462. db_ = NULL;
  463. DestroyDB(FLAGS_db, Options());
  464. Open();
  465. Start(); // Do not count time taken to destroy/open
  466. }
  467. if (num_entries != num_) {
  468. char msg[100];
  469. snprintf(msg, sizeof(msg), "(%d ops)", num_entries);
  470. message_ = msg;
  471. }
  472. WriteBatch batch;
  473. Status s;
  474. std::string val;
  475. for (int i = 0; i < num_entries; i += entries_per_batch) {
  476. batch.Clear();
  477. for (int j = 0; j < entries_per_batch; j++) {
  478. const int k = (order == SEQUENTIAL) ? i+j : (rand_.Next() % FLAGS_num);
  479. char key[100];
  480. snprintf(key, sizeof(key), "%016d", k);
  481. batch.Put(key, gen_.Generate(value_size));
  482. bytes_ += value_size + strlen(key);
  483. FinishedSingleOp();
  484. }
  485. s = db_->Write(options, &batch);
  486. if (!s.ok()) {
  487. fprintf(stderr, "put error: %s\n", s.ToString().c_str());
  488. exit(1);
  489. }
  490. }
  491. }
  492. void ReadSequential() {
  493. Iterator* iter = db_->NewIterator(ReadOptions());
  494. int i = 0;
  495. for (iter->SeekToFirst(); i < reads_ && iter->Valid(); iter->Next()) {
  496. bytes_ += iter->key().size() + iter->value().size();
  497. FinishedSingleOp();
  498. ++i;
  499. }
  500. delete iter;
  501. }
  502. void ReadReverse() {
  503. Iterator* iter = db_->NewIterator(ReadOptions());
  504. int i = 0;
  505. for (iter->SeekToLast(); i < reads_ && iter->Valid(); iter->Prev()) {
  506. bytes_ += iter->key().size() + iter->value().size();
  507. FinishedSingleOp();
  508. ++i;
  509. }
  510. delete iter;
  511. }
  512. void ReadRandom() {
  513. ReadOptions options;
  514. std::string value;
  515. for (int i = 0; i < reads_; i++) {
  516. char key[100];
  517. const int k = rand_.Next() % FLAGS_num;
  518. snprintf(key, sizeof(key), "%016d", k);
  519. db_->Get(options, key, &value);
  520. FinishedSingleOp();
  521. }
  522. }
  523. void ReadHot() {
  524. ReadOptions options;
  525. std::string value;
  526. const int range = (FLAGS_num + 99) / 100;
  527. for (int i = 0; i < reads_; i++) {
  528. char key[100];
  529. const int k = rand_.Next() % range;
  530. snprintf(key, sizeof(key), "%016d", k);
  531. db_->Get(options, key, &value);
  532. FinishedSingleOp();
  533. }
  534. }
  535. void Compact() {
  536. DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
  537. dbi->TEST_CompactMemTable();
  538. int max_level_with_files = 1;
  539. for (int level = 1; level < config::kNumLevels; level++) {
  540. std::string property;
  541. char name[100];
  542. snprintf(name, sizeof(name), "leveldb.num-files-at-level%d", level);
  543. if (db_->GetProperty(name, &property) && atoi(property.c_str()) > 0) {
  544. max_level_with_files = level;
  545. }
  546. }
  547. for (int level = 0; level < max_level_with_files; level++) {
  548. dbi->TEST_CompactRange(level, "", "~");
  549. }
  550. }
  551. void PrintStats() {
  552. std::string stats;
  553. if (!db_->GetProperty("leveldb.stats", &stats)) {
  554. message_ = "(failed)";
  555. } else {
  556. post_message_ = stats;
  557. }
  558. }
  559. static void WriteToFile(void* arg, const char* buf, int n) {
  560. reinterpret_cast<WritableFile*>(arg)->Append(Slice(buf, n));
  561. }
  562. void HeapProfile() {
  563. char fname[100];
  564. snprintf(fname, sizeof(fname), "%s/heap-%04d", FLAGS_db, ++heap_counter_);
  565. WritableFile* file;
  566. Status s = Env::Default()->NewWritableFile(fname, &file);
  567. if (!s.ok()) {
  568. message_ = s.ToString();
  569. return;
  570. }
  571. bool ok = port::GetHeapProfile(WriteToFile, file);
  572. delete file;
  573. if (!ok) {
  574. message_ = "not supported";
  575. Env::Default()->DeleteFile(fname);
  576. }
  577. }
  578. };
  579. }
  580. int main(int argc, char** argv) {
  581. FLAGS_write_buffer_size = leveldb::Options().write_buffer_size;
  582. FLAGS_open_files = leveldb::Options().max_open_files;
  583. for (int i = 1; i < argc; i++) {
  584. double d;
  585. int n;
  586. char junk;
  587. if (leveldb::Slice(argv[i]).starts_with("--benchmarks=")) {
  588. FLAGS_benchmarks = argv[i] + strlen("--benchmarks=");
  589. } else if (sscanf(argv[i], "--compression_ratio=%lf%c", &d, &junk) == 1) {
  590. FLAGS_compression_ratio = d;
  591. } else if (sscanf(argv[i], "--histogram=%d%c", &n, &junk) == 1 &&
  592. (n == 0 || n == 1)) {
  593. FLAGS_histogram = n;
  594. } else if (sscanf(argv[i], "--use_existing_db=%d%c", &n, &junk) == 1 &&
  595. (n == 0 || n == 1)) {
  596. FLAGS_use_existing_db = n;
  597. } else if (sscanf(argv[i], "--num=%d%c", &n, &junk) == 1) {
  598. FLAGS_num = n;
  599. } else if (sscanf(argv[i], "--reads=%d%c", &n, &junk) == 1) {
  600. FLAGS_reads = n;
  601. } else if (sscanf(argv[i], "--value_size=%d%c", &n, &junk) == 1) {
  602. FLAGS_value_size = n;
  603. } else if (sscanf(argv[i], "--write_buffer_size=%d%c", &n, &junk) == 1) {
  604. FLAGS_write_buffer_size = n;
  605. } else if (sscanf(argv[i], "--cache_size=%d%c", &n, &junk) == 1) {
  606. FLAGS_cache_size = n;
  607. } else if (sscanf(argv[i], "--open_files=%d%c", &n, &junk) == 1) {
  608. FLAGS_open_files = n;
  609. } else if (strncmp(argv[i], "--db=", 5) == 0) {
  610. FLAGS_db = argv[i] + 5;
  611. } else {
  612. fprintf(stderr, "Invalid flag '%s'\n", argv[i]);
  613. exit(1);
  614. }
  615. }
  616. leveldb::Benchmark benchmark;
  617. benchmark.Run();
  618. return 0;
  619. }