加特林代理配置

Posted

技术标签:

【中文标题】加特林代理配置【英文标题】:Gatling proxy configuration 【发布时间】:2013-09-14 17:58:07 【问题描述】:

这是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:

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

【问题讨论】:

【参考方案1】:

自 2013 年最初回答该问题以来,情况发生了变化。他们的documentation link改了,proxy的函数定义改成了:

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

【讨论】:

对于袜子(例如 tor/etc):val httpConf = http.proxy(Proxy("mySocksProxyHost", 9050).socks5),或类似*.socks4)【参考方案2】:

如documentation中所说,第一个参数是主机名,不是url。

请使用:

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

【讨论】:

这行得通。如果使用上述方法,是否仍需要修改 conf/gatling.conf 以包含代理?还是两者都是必需的,或者任何一个都可以? HttpProtocol 覆盖 gatling.conf 中定义的内容。 这是一个旧线程,但我可以使用 socks 代理而不是 http 代理吗? http.proxy(Proxy("proxy.server.address", 8081)) 是最新的语法

以上是关于加特林代理配置的主要内容,如果未能解决你的问题,请参考以下文章

React配置代理

React 脚手架配置代理

react脚手架配置代理

haproxy 配置mysql的代理

nginx反向代理配置去除前缀

使用 nginx 反向代理 sqlserver 访问 配置(转)