Last active
August 4, 2021 10:48
-
-
Save miminashi/ed3e5050c4b3d829b69b1bb9caad4edd to your computer and use it in GitHub Desktop.
並列実行するとログが破壊される場合の再現(ファイル3つとも同じディレクトリに置いてね)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# run.sh | |
# | |
# 使い方: | |
# chmod +x run_mp.sh | |
# ./run.sh | |
# | |
COUNT=100 | |
mkdir -p log | |
rm log/chat_log.txt | |
s="$(seq 1 ${COUNT} | tr '\n' ' ')" | |
time sh -c " | |
for i in ${s}; do | |
ruby write.rb | |
done | |
printf '実行にかかった時間: ' | |
" | |
printf 'ログの行数: %s\n' "$(wc -l log/chat_log.txt | sed 's/^ *//' | cut -d ' ' -f 1)" | |
printf '壊れている行数: ' | |
grep -v -c -e "いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせすん" < log/chat_log.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# run_mp.sh | |
# | |
# 使い方: | |
# chmod +x run_mp.sh | |
# ./run_mp.sh | |
# | |
COUNT=100 | |
mkdir -p log | |
rm log/chat_log.txt | |
s="$(seq 1 ${COUNT} | tr '\n' ' ')" | |
time sh -c " | |
for i in ${s}; do | |
ruby write.rb & | |
done | |
wait | |
printf '実行にかかった時間: ' | |
" | |
printf 'ログの行数: %s\n' "$(wc -l log/chat_log.txt | sed 's/^ *//' | cut -d ' ' -f 1)" | |
printf '壊れている行数: ' | |
grep -v -c -e "いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせすん" < log/chat_log.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_string = "いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせすん" | |
def write_to_file(message) | |
File.open('./log/chat_log.txt', 'a+') {|file| | |
message.each_char {|c| | |
file.write(c) | |
file.flush | |
} | |
file.write("\n") | |
} | |
end | |
write_to_file(test_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment