加特林代理配置

时间:2013-09-10 21:12:47

标签: scala proxy stress-testing gatling webapplicationstresstool

这是this question的后续内容。我使用相同的配置。但是,我正在尝试通过代理服务器使用内部网站。我不确定以下是否在模拟中配置代理的正确方法。

 val httpConf = http.proxy("http://proxy.server.address", 8080)

这是我修改后的代码。

package foo 
import io.gatling.core.Predef._
import io.gatling.core.session.Expression
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import io.gatling.http.Headers.Names._
import io.gatling.http.Headers.Values._
import scala.concurrent.duration._
import bootstrap._
import assertions._

class SimpleSimulation extends Simulation { 
    val httpConf = http.proxy("http://proxy.server.address", 8080)

    val scn = scenario("My scenario")
    .exec(http("My Page")
    .get("http://10.128.3.232:9201/index.html")) 

 setUp(scn.inject(atOnce(50 user))).protocols(httpConf) 

}

我还修改了conf/gatling.conf以包含代理。我不确定配置代理的正确方法是什么。

http {
        #baseUrls = ""                                                          # default value for the base HTTP URLs
        proxy {
                host = "http://proxy.server.address"                                                               # proxy host (blank means no proxy)
                port = 8080                                                             # HTTP port
                securedPort = -1                                                # HTTPS port (-1 means no HTTPS proxy)
                #username = ""                                                  # proxy username (blank means no credentials)
                #password = ""                                                  # proxy password
        } 

运行模拟时出现以下异常。

17:09:15.654 [INFO ] i.g.h.a.HttpRequestAction - Sending request 'My Page': scenario 'My scenario', userId #49
17:09:15.655 [WARN ] i.g.h.a.AsyncHandler - Request 'My Page' failed
java.nio.channels.UnresolvedAddressException: null
    at sun.nio.ch.Net.checkAddress(Net.java:36) ~[na:1.6.0_51]
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:512) ~[na:1.6.0_51]
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:108) ~[netty-3.6.6.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:70) ~[netty-3.6.6.Final.jar:na]
    at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:54) ~[netty-3.6.6.Final.jar:na]
    at org.jboss.netty.handler.codec.http.HttpClientCodec.handleDownstream(HttpClientCodec.java:97) ~[netty-3.6.6.Final.jar:na]
    at org.jboss.netty.handler.stream.ChunkedWriteHandler.handleDownstream(ChunkedWriteHandler.java:109) ~[netty-3.6.6.Final.jar:na]
    at org.jboss.netty.channel.Channels.connect(Channels.java:634) ~[netty-3.6.6.Final.jar:na]
    at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:207) ~[netty-3.6.6.Final.jar:na]
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:229) ~[netty-3.6.6.Final.jar:na]
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:182) ~[netty-3.6.6.Final.jar:na]
    at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.doConnect(NettyAsyncHttpProvider.java:1026) [async-http-client-1.7.19.20130706.jar:na]
Wrapped by: java.net.ConnectException: http://10.128.3.232:9201/index.html
    at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:103) ~[async-http-client-1.7.19.20130706.jar:na]
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:427) [netty-3.6.6.Final.jar:na]
    at org.jboss.netty.channel.DefaultChannelFuture.addListener(DefaultChannelFuture.java:145) [netty-3.6.6.Final.jar:na]
    at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.doConnect(NettyAsyncHttpProvider.java:1068) [async-http-client-1.7.19.20130706.jar:na]
    at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.execute(NettyAsyncHttpProvider.java:890) [async-http-client-1.7.19.20130706.jar:na]
    at com.ning.http.client.AsyncHttpClient.executeRequest(AsyncHttpClient.java:520) [async-http-client-1.7.19.20130706.jar:na]
    at io.gatling.http.ahc.HttpClient$.sendHttpRequest(HttpClient.scala:144) [gatling-http-2.0.0-M3a.jar:na]
    at io.gatling.http.action.HttpRequestAction.io$gatling$http$action$HttpRequestAction$$sendRequest$1(HttpRequestAction.scala:75) [gatling-http-2.0.0-M3a.jar:na]
    at io.gatling.http.action.HttpRequestAction$$anonfun$executeOrFail$1$$anonfun$apply$2.apply(HttpRequestAction.scala:84) [gatling-http-2.0.0-M3a.jar:na]
    at io.gatling.http.action.HttpRequestAction$$anonfun$executeOrFail$1$$anonfun$apply$2.apply(HttpRequestAction.scala:81) [gatling-http-2.0.0-M3a.jar:na]
    at io.gatling.core.validation.Success.map(Validation.scala:27) [gatling-core-2.0.0-M3a.jar:na]
    at io.gatling.http.action.HttpRequestAction$$anonfun$executeOrFail$1.apply(HttpRequestAction.scala:81) [gatling-http-2.0.0-M3a.jar:na]
    at io.gatling.http.action.HttpRequestAction$$anonfun$executeOrFail$1.apply(HttpRequestAction.scala:80) [gatling-http-2.0.0-M3a.jar:na]
    at io.gatling.core.validation.Success.flatMap(Validation.scala:28) [gatling-core-2.0.0-M3a.jar:na]
    at io.gatling.http.action.HttpRequestAction.executeOrFail(HttpRequestAction.scala:80) [gatling-http-2.0.0-M3a.jar:na]
    at io.gatling.core.action.Failable$class.execute(Actions.scala:82) [gatling-core-2.0.0-M3a.jar:na]
    at io.gatling.http.action.HttpRequestAction.execute(HttpRequestAction.scala:54) [gatling-http-2.0.0-M3a.jar:na]
    at io.gatling.core.action.Action$$anonfun$receive$1.applyOrElse(Actions.scala:42) [gatling-core-2.0.0-M3a.jar:na]
    at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:166) [scala-library-2.10.2.jar:na]
    at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425) [akka-actor_2.10-2.1.4.jar:na]
    at akka.actor.ActorCell.invoke(ActorCell.scala:386) [akka-actor_2.10-2.1.4.jar:na]
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230) [akka-actor_2.10-2.1.4.jar:na]
    at akka.dispatch.Mailbox.run(Mailbox.scala:212) [akka-actor_2.10-2.1.4.jar:na]
    at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:506) [akka-actor_2.10-2.1.4.jar:na]
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.10.2.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.10.2.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.10.2.jar:na]
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.10.2.jar:na]
17:09:15.656 [WARN ] i.g.h.a.AsyncHandlerActor - Request 'My Page' failed : http://10.128.3.232:9201/emontage/home.html
17:09:15.656 [DEBUG] i.g.h.a.AsyncHandlerActor - 
>>>>>>>>>>>>>>>>>>>>>>>>>>
Request:
My Page: KO http://10.128.3.232:9201/index.html
=========================
Session:
Session(My scenario,49,Map(),1378847355391,0,List(),List(KO),List(),List())
=========================
HTTP request:
GET http://10.128.3.232:9201/index.html
=========================
HTTP response:

<<<<<<<<<<<<<<<<<<<<<<<<<

2 个答案:

答案 0 :(得分:13)

自2013年问题最初得到解答以来,情况发生了变化。他们的documentation link已更改,代理的函数定义已更改为:

val httpConf = http.proxy(Proxy("myProxyHost", 8080))

答案 1 :(得分:5)

documentation所述,第一个参数是主机名,而不是网址。

请使用:

val httpConf = http.proxy("proxy.server.address", 8080)