commit 6238be66c8eed73f9a36704ba3a3d0a218b55bea
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Mon Sep 10 12:27:00 2012 -0400
Store status bandwidth/weights files in subdirectories.
Right now, there are 300k bandwidth history files and 140k weights history
files in Onionoo's status directory. weasel suggests to store those files
in subdirectories, e.g., 1/2/1234567.. to speed up access. Let's do that.
The real fix is to use a database, of course. But until we have that,
let's try to make the file system based solution not suck.
---
.../torproject/onionoo/BandwidthDataWriter.java | 8 ++++++--
src/org/torproject/onionoo/WeightsDataWriter.java | 8 ++++++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/org/torproject/onionoo/BandwidthDataWriter.java b/src/org/torproject/onionoo/BandwidthDataWriter.java
index 4f86371..7543863 100644
--- a/src/org/torproject/onionoo/BandwidthDataWriter.java
+++ b/src/org/torproject/onionoo/BandwidthDataWriter.java
@@ -135,7 +135,9 @@ public class BandwidthDataWriter {
private void readHistoryFromDisk(String fingerprint,
SortedMap<Long, long[]> writeHistory,
SortedMap<Long, long[]> readHistory) {
- File historyFile = new File("status/bandwidth", fingerprint);
+ File historyFile = new File(String.format("status/bandwidth/%s/%s/%s",
+ fingerprint.substring(0, 1), fingerprint.substring(1, 2),
+ fingerprint));
if (historyFile.exists()) {
try {
BufferedReader br = new BufferedReader(new FileReader(
@@ -226,7 +228,9 @@ public class BandwidthDataWriter {
private void writeHistoryToDisk(String fingerprint,
SortedMap<Long, long[]> writeHistory,
SortedMap<Long, long[]> readHistory) {
- File historyFile = new File("status/bandwidth", fingerprint);
+ File historyFile = new File(String.format("status/bandwidth/%s/%s/%s",
+ fingerprint.substring(0, 1), fingerprint.substring(1, 2),
+ fingerprint));
try {
historyFile.getParentFile().mkdirs();
BufferedWriter bw = new BufferedWriter(new FileWriter(historyFile));
diff --git a/src/org/torproject/onionoo/WeightsDataWriter.java b/src/org/torproject/onionoo/WeightsDataWriter.java
index b02e0c0..67c07dc 100644
--- a/src/org/torproject/onionoo/WeightsDataWriter.java
+++ b/src/org/torproject/onionoo/WeightsDataWriter.java
@@ -276,7 +276,9 @@ public class WeightsDataWriter {
return a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
}
});
- File historyFile = new File("status/weights", fingerprint);
+ File historyFile = new File(String.format("status/weights/%s/%s/%s",
+ fingerprint.substring(0, 1), fingerprint.substring(1, 2),
+ fingerprint));
if (historyFile.exists()) {
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
@@ -377,7 +379,9 @@ public class WeightsDataWriter {
private void writeHistoryToDisk(String fingerprint,
SortedMap<long[], double[]> history) {
- File historyFile = new File("status/weights", fingerprint);
+ File historyFile = new File(String.format("status/weights/%s/%s/%s",
+ fingerprint.substring(0, 1), fingerprint.substring(1, 2),
+ fingerprint));
try {
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");