为什么writeoptions.sync在false和true下,测试出的结果差不多呢
我用php操作leveldb,为什么writeoptions.sync在false和true下,测试出的结果差不多呢,都是45W左右
按理说,这个选项对性能影响很大啊,应该差很多啊?
按理说,这个选项对性能影响很大啊,应该差很多啊?
<?php /* defau lt open options */ $options = array( 'create_if_missing' => true, // if the specified database didn't exist will create a new one 'error_if_exists' => false, // if the opened database exsits will throw exception 'paranoid_checks' => false, 'block_cache_size' => 32 * 1024 * 1024, 'write_buffer_size' => 2000 * 1024 * 1024, 'block_size' => 4096, 'max_open_files' => 1000, 'block_restart_interval' => 16, 'compression' => LEVELDB_SNAPPY_COMPRESSION, 'comparator' => NULL, // any callable parameter which returns 0, -1, 1 ); /* default readoptions */ $readoptions = array( 'verify_check_sum' => false, 'fill_cache' => true, 'snapshot' => null ); /* default write options */ $writeoptions = array( 'sync' => true, ); $db = new LevelDB("/usr/local/leveldb/testdb", $options, $readoptions, $writeoptions); for($j=0;$j<100;$j++){ $ss=microtime(true); echo 'starting at '.$ss." ...n"; for($i=0;$i<500000;$i++){ $db->put("Key".$j.$i, "Value"); $db->get("Key".$j.$i); $db->set("Key".$j.$i, "Value"); } $ee=microtime(true); echo 'complite at '.$ee." !n"; echo $ee-$ss . "n"; echo 500000/($ee-$ss)."n"; echo "sleep 10S ... n"; sleep(10) }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(2)
心舞飞扬2021-11-29 21:50:26
有人给我了一段这样的解释,是什么意思呢?
This may be POSIX specific, but it appears that leveldb::WriteOptions::sync doesn't actually guarantee that the write will go to disk, at least for batch writes. In a production setting with sync set to true and batch writes (relatively small writes) happening continually on sub-second intervals, it takes leveldb around 5 minutes before it syncs any data to disk.
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我找到原因了
$db =new LevelDB("/usr/local/leveldb/testdb",$options,$readoptions,$writeoptions);
这条语句中的$readoptions,$writeoptions并不会在后面的set/get中生效
set/get实现中会重新读传入的参数
所以正确用法是应该在set/get中传入读写选项参数
至于说在sync生效的情况下OS到底有没有同步写到磁盘,这个就不太清楚了