浏览代码

optimisations

Simon 2 年之前
父节点
当前提交
7c3a2a8c7d
共有 3 个文件被更改,包括 16 次插入11 次删除
  1. 2 2
      client/client.go
  2. 8 4
      leader/leader.go
  3. 6 5
      lib/databaseRead.go

+ 2 - 2
client/client.go

@@ -42,7 +42,7 @@ type tweet struct {
 const leader string = "127.0.0.1:4441"
 
 //needs to be changed at leader/follower/client at the same time
-const numClients = 500
+const numClients = 2000
 
 //mylimit=8000
 //sudo prlimit --nofile=$mylimit --pid $$; ulimit -n $mylimit
@@ -665,7 +665,7 @@ func getRealTweet(clientNumber int) []byte {
 
 		//skips round 1, cause of 90% publisher rate
 		if round == 1 {
-			//break
+			break
 		}
 
 		lineArr := strings.Split(scanner.Text(), ", \"hashtags\"")

+ 8 - 4
leader/leader.go

@@ -64,10 +64,14 @@ const roundsBeforeUpdate = 2
 const neededSubscriptions = 5
 const numThreads = 12
 const dataLength = 256
-const minDBWriteSize = 1000
-const numClients = 500
+const numClients = 2000
+const minDBWriteSize = numClients * 0.35
 
-var dbWriteSize float64 = numClients * 19.5
+//riposte says 19.5
+const dbSizeFactor = 5
+const publisherGuess = 0.15
+
+var dbWriteSize float64 = numClients * dbSizeFactor * publisherGuess
 
 //this is the number of positions for auditing
 var extraPositions int = 2
@@ -788,7 +792,7 @@ func phase2(followerConnection net.Conn) {
 	}
 
 	//calculates the dbWriteSize for this round
-	dbWriteSize = math.Ceil(19.5 * float64(publisherAverage))
+	dbWriteSize = math.Ceil(dbSizeFactor * float64(publisherAverage))
 
 	if dbWriteSize < minDBWriteSize {
 		dbWriteSize = minDBWriteSize

+ 6 - 5
lib/databaseRead.go

@@ -97,7 +97,7 @@ func GetTweets(pirQuery []byte, dataLength int, whereFrom int, pubKey [32]byte)
 		}
 	}
 
-	return tweetsToByteArray(tweetsToReturn, whereFrom, wantedTopics)
+	return tweetsToByteArray(tweetsToReturn, whereFrom, wantedTopics, dataLength)
 }
 
 func getNamesForTopics(wantedIndices []byte, whereFrom int) []string {
@@ -118,9 +118,10 @@ func getNamesForTopics(wantedIndices []byte, whereFrom int) []string {
 }
 
 //transform struct to byte array for sending
-func tweetsToByteArray(tweetsToReturn [][]Tweet, whereFrom int, wantedTopics []string) []byte {
-	//50 is an estimated nr that works, there probably is a smarter way to do this
-	minimumBlockSize := 50 * maxTweetAmount(whereFrom)
+func tweetsToByteArray(tweetsToReturn [][]Tweet, whereFrom int, wantedTopics []string, dataLength int) []byte {
+	//factor is an estimated nr that works, there probably is a smarter way to do this
+	factor := 0.4
+	minimumBlockSize := int(factor * float64(dataLength*maxLength(whereFrom)))
 
 	tweetsAsBytes := make([]byte, minimumBlockSize)
 	for _, block := range tweetsToReturn {
@@ -172,7 +173,7 @@ func tweetsToByteArray(tweetsToReturn [][]Tweet, whereFrom int, wantedTopics []s
 	return tweetsAsBytes
 }
 
-func maxTweetAmount(whereFrom int) int {
+func maxLength(whereFrom int) int {
 	tmpdb := dbR
 	if whereFrom == 1 {
 		tmpdb = archive