Commit 6f04adacb47006f3a76c6010c97c93ae3ae35cb0

Authored by don ago
1 parent 5caf037ee9
Exists in master

안되는거수정

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

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