Go language concurrent acquisition HLS, test streaming media service pull-flow pressure

Source: Internet
Author: User

Two days ago, our development brothers finally implemented and deployed our streaming media overall solution, although all are open source projects, but we have to test the performance of the service internally, this task was thrown to me.

First of all, the performance loss of the internal links, testing the single-source, multi-channel streaming scene.

Using Golang, write the following program:

Package Main

Import (
"Bytes"
"FMT"
"IO"
"Net/http"
"OS"
"RegExp"
"StrConv"
"Time"
)

/*this application is used-to-get RTSP stream data for me*/

Func Main () {
var Host = ""
var Tim = 1
For _, A: = Range OS. Args[1:] {
If string (a) = = "--help" {
FMT. PRINTLN ("Usage is-g input goal")
FMT. PRINTLN ("Usage is-t input threat num")
}
If string (a) = = "/?" {
FMT. PRINTLN ("Usage is-g input goal")
FMT. PRINTLN ("Usage is-t input threat num")
}
m, err: = RegExp. Matchstring ("^-[g,t]", String (a))
Reg: = RegExp. Mustcompile (' ^-[g,t] ')
if M {
Host: = Reg. Findallstring (String (a),-2) [0]
If host = = "-G" {
pp: = []rune (a)
host = string (Pp[2:len (PP)])
}
If host = = "-T" {
pp: = []rune (a)
Tim, err: = StrConv. Atoi (String (Pp[2:len (PP))))
Tim = Tim
If err! = Nil {
FMT. Printf ("Input number Oh")
Return
}
}
}
If err! = Nil {
FMT. PRINTLN (Err)
return
}
}

if Host = = "" {
Fmt. PRINTLN ("Please input/? For help ")
Fmt. Println (String (Tim))
Return
} else {
For i: = 1; i < Tim; i++ {
Fmt. Printf ("Pull up%d file streams \ n", i)
Go Gethttphls (Host)
}
Fmt. Println ("Pull up the main thread file stream")
Gethttphls (Host)
}
}

Func Gethttphls (H string) {
Req, _: = http. Newrequest ("GET", h, Nil)
RESP, err: = http. Defaultclient.do (req)
If err! = Nil {
Handle error
Fmt. PRINTLN (ERR)
Return
}
Defer resp. Body.close ()

Here we open a loop to read stream
Buffer: = Make ([]byte, 8192)
for {
Time. Sleep (500)
_, _ = resp. Body.read (buffer)
}
}

  

Use the steps: 1, use the command: Go build get_hls.go, compile 2, use:./get_hls-ghttp://127.0.0.1:8082/live/20_unv01_1.flv-t1000, Get 1000 streams in such a way, and discard the stream directly

Description

1, my side to the Internet to download a stream of streaming tools, when used, streaming media pull tool performance consumption than my SRS consumption is also larger, and a period of time will automatically kill, so write the above procedures to bury the pit

2, because the company LAN is a LAN, there is no way to test the pressure of our services, so here are used back to the way in use, the single-channel rate of 4Mbps or so, pulling 22 road code stream on the

Above this program is very meanness, hope to have a master to guide, the program, the back of the buffer is read into the garbage inside, but if you can not read, directly new processing, it should be more effective.

Go language concurrent acquisition HLS, test streaming media service pull-flow pressure

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.