Commit 8033a25c88bd2dc7530a877b0e794610634c26fb

Authored by steve ago
1 parent 105d142379
Exists in master

로그 전송 시 1줄~3000줄까지 랜덤으로 끊어 각각 전송 하도록 처리

Showing 1 changed file with 72 additions and 18 deletions Side-by-side Diff

app/SendLog.scala View file @ 8033a25
1 1 import java.io.OutputStreamWriter
2 2 import java.net.URI
3 3  
  4 +import org.apache.commons.lang.time
  5 +import org.apache.commons.lang.time.StopWatch
  6 +import scala.util.Random
  7 +import scala.util.control.Breaks._
4 8 /**
5 9 * Created by soochanlee on 2015. 3. 18..
6 10 */
7 11  
8 12  
9 13  
10 14  
11 15  
12 16  
13 17  
14 18  
15 19  
16 20  
17 21  
... ... @@ -14,37 +18,85 @@
14 18 //scala.io.Source.fromURL(("http://localhost:9000")).getLines().next()
15 19 val file_list = dir.listFiles.map(x=>x.getAbsoluteFile)
16 20  
17   - for (a <- 1 to 2) {
  21 + var total_line = 0
  22 + var cur_line = 0
  23 + var rand_val = Random.nextInt(3000) + 1
  24 +
  25 + var url = new java.net.URL("http://localhost:8081/log")
  26 + var httpcon = url.openConnection.asInstanceOf[java.net.HttpURLConnection]
  27 + httpcon.setRequestMethod("POST")
  28 +
  29 + httpcon.setDoOutput(true)
  30 + httpcon.setDoInput(true)
  31 + var out = httpcon.getOutputStream
  32 + var w = new OutputStreamWriter(out)
  33 +
  34 + val clock = new StopWatch()
  35 + clock.start()
  36 + for (a <- 1 to 500000) {
18 37 for (file <- file_list) {
19 38  
20   - println(file)
21   - val str = scala.io.Source.fromFile(file)("UTF8").getLines.mkString("\n")
  39 + //println(file)
  40 + //val str = scala.io.Source.fromFile(file)("UTF8").getLines.mkString("\n")
  41 + val str_array = scala.io.Source.fromFile(file)("UTF8").getLines.toArray
22 42  
  43 + for (x <- str_array) {
  44 + total_line += 1
  45 + cur_line += 1
  46 + w.write(x + "\n")
23 47  
24   - val url = new java.net.URL("http://localhost:8081/log")
25   - val httpcon = url.openConnection.asInstanceOf[java.net.HttpURLConnection]
26   - httpcon.setRequestMethod("POST")
27 48  
28   - httpcon.setDoOutput(true)
29   - httpcon.setDoInput(true)
30   - val out = httpcon.getOutputStream
31   - val w = new OutputStreamWriter(out)
  49 + if (cur_line == rand_val) {
32 50  
33   - println(str.length)
34   - w.write(str)
  51 + w.flush()
35 52  
36   - val in = httpcon.getInputStream
37   - val s = scala.io.Source.fromInputStream(in)("UTF8")
38   - s.mkString
39 53  
  54 + val in = httpcon.getInputStream
  55 + val s = scala.io.Source.fromInputStream(in)("UTF8")
  56 + val r_text = s.mkString
  57 + //println(r_text)
  58 + w.close()
  59 + out.close()
  60 + httpcon.disconnect()
40 61  
41   - w.close()
42   - out.close()
43   - httpcon.disconnect()
  62 + url = new java.net.URL("http://localhost:8081/log")
  63 + httpcon = url.openConnection.asInstanceOf[java.net.HttpURLConnection]
  64 + httpcon.setRequestMethod("POST")
44 65  
  66 + httpcon.setDoOutput(true)
  67 + httpcon.setDoInput(true)
  68 + out = httpcon.getOutputStream
  69 + w = new OutputStreamWriter(out)
45 70  
  71 + cur_line = 0
  72 + rand_val = Random.nextInt(3000) + 1
  73 + }
  74 +
  75 + if (total_line % 1000000 == 0) {
  76 + println("total line : "+total_line)
  77 + println(clock.getTime() * 1000 + " sec")
  78 + println(total_line / clock.getTime * 1000 + " line/sec")
  79 + }
  80 + }
  81 +
46 82 }
47 83 }
  84 + if (cur_line != 0) {
  85 + w.flush()
  86 +
  87 + val in = httpcon.getInputStream
  88 + val s = scala.io.Source.fromInputStream(in)("UTF8")
  89 + val r_text = s.mkString
  90 + //println(r_text)
  91 + w.close()
  92 + out.close()
  93 + httpcon.disconnect()
  94 + }
  95 + clock.stop()
  96 + println("total line : "+total_line)
  97 + println(clock.getTime() * 1000 + " sec")
  98 + println(total_line / clock.getTime * 1000 + " line/sec")
  99 +
48 100 }
49 101  
50 102 }