caspercloud

package module
v0.0.0-...-aedc885 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2015 License: MIT Imports: 34 Imported by: 0

README

Casper Cloud

Travis Status

基准测试

我们Mock了一个服务他的平均响应时间非常短,他产生的HTML非常简单

<html><head><title>Hello World</title></head><body><h1>Hello World</h1></body></html>

然后我们测试三种下载方式的下载时间

1. curl
2. golang http.Client
3. casper js

结果如下

BenchmarkCurl-4         2000        7960292 ns/op
BenchmarkHttpClient-4   100000      179471 ns/op
BenchmarkCasperJs-4     5           3091975091 ns/op

可以看到,Curl启动进程的时间花费了7ms,http.Client启动进程的时间为0, 而CasperJs启动进程的时间最长,大概需要3s。

但是,如果节省CasperJs打开进程的时间,那么实际下载时间是多少?

我们写了两段js

mock.js

var casper = require("casper").create();
casper.start("http://127.0.0.1:20893/hello", function(){
    console.log(this.getHTML());
});
casper.run();

mock_100.js

var casper = require("casper").create();
casper.start("http://127.0.0.1:20893/hello", function(){
    console.log(this.getHTML());
}).repeat(99, function(){
    casper.thenOpen("http://127.0.0.1:20893/hello", function(){
        console.log(this.getHTML());
    });
});
casper.run();

在mock.js中,我们打开一次casperjs只下载一个链接,而在mock_100.js中,我们打开一次下载100个链接。然后我们在服务端让程序10ms返回。再做一次测试,结果如下:

BenchmarkCasperJs-4        20   2824344729 ns/op
BenchmarkCasperJs100-4         5    9634887107 ns/op

可以看到,在批量下载的程序里,一次下载的时间是 (9635 - 2824) / 99 = 68ms

同样的,我们也对比一下curl的单次下载和批量下载,结果如下

BenchmarkCurl-4     2000      22667633 ns/op
BenchmarkCurl100-4        30    1202024886 ns/op

可以看到,curl的一次下载时间是 (1202 - 22) / 99 = 11ms

从而可以看到,在单次下载中,casperjs的耗时是curl的6倍左右。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDownloads

func LoadDownloads(fs []string)

func ParseFile

func ParseFile(fn string) error

func Pop3ReceiveMail

func Pop3ReceiveMail(username, password string) ([]string, error)

func PostDataToSlack

func PostDataToSlack(msg, channel string) bool

func UploadImage

func UploadImage(path string) string

Types

type CasperCmd

type CasperCmd struct {
	// contains filtered or unexported fields
}

func NewCasperCmd

func NewCasperCmd(id, tmpl, proxyServer string) *CasperCmd

func (*CasperCmd) DecodePassword

func (self *CasperCmd) DecodePassword(p string) string

func (*CasperCmd) Finished

func (self *CasperCmd) Finished() bool

func (*CasperCmd) GetArgsValue

func (self *CasperCmd) GetArgsValue(key string) string

func (*CasperCmd) GetId

func (self *CasperCmd) GetId() string

func (*CasperCmd) GetMessage

func (self *CasperCmd) GetMessage() map[string]interface{}

func (*CasperCmd) GetStatus

func (self *CasperCmd) GetStatus() int

func (*CasperCmd) SetInputArgs

func (self *CasperCmd) SetInputArgs(input map[string]string)

type CasperOutput

type CasperOutput struct {
	Downloads []string `json:"downloads"`
	Mails     []Mail   `json:"mails"`
}

type CasperServer

type CasperServer struct {
	Host string
	// contains filtered or unexported fields
}

func NewCasperServer

func NewCasperServer(host string) *CasperServer

func (*CasperServer) Process

func (self *CasperServer) Process(params url.Values) string

func (*CasperServer) ServeHTTP

func (self *CasperServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*CasperServer) ServeWebSocket

func (self *CasperServer) ServeWebSocket(ws *websocket.Conn)

type Command

type Command interface {
	GetMessage() map[string]interface{}
	GetStatus() int
	SetInputArgs(map[string]string)
	Finished() bool
	GetId() string
}

type FakeCmd

type FakeCmd struct {
	// contains filtered or unexported fields
}

func NewFakeCmd

func NewFakeCmd(id string) *FakeCmd

func (*FakeCmd) Finished

func (fakeCmd *FakeCmd) Finished() bool

func (*FakeCmd) GetId

func (fakeCmd *FakeCmd) GetId() string

func (*FakeCmd) GetMessage

func (fakeCmd *FakeCmd) GetMessage() map[string]string

func (*FakeCmd) Run

func (fakeCmd *FakeCmd) Run()

func (*FakeCmd) SetCmd

func (fakeCmd *FakeCmd) SetCmd(cmd string)

func (*FakeCmd) SetInputArgs

func (fakeCmd *FakeCmd) SetInputArgs(input map[string]string)

type Mail

type Mail struct {
	From  string `json:"from"`
	Title string `json:"title"`
}

type MailProcessor

type MailProcessor struct {
}

func NewMailProcessor

func NewMailProcessor() *MailProcessor

func (*MailProcessor) Process

func (p *MailProcessor) Process(metaInfo map[string]string, downloads []string) bool

type ServerData

type ServerData struct {
	// contains filtered or unexported fields
}

func NewServerData

func NewServerData() *ServerData

func (*ServerData) GetCommand

func (self *ServerData) GetCommand(id string) Command

func (*ServerData) GetNewCommand

func (self *ServerData) GetNewCommand(tmpl, proxyServer string) Command

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL