web test performance tool / gatling

 

- gatling 压测

Gatling 是一个用于进行负载测试的开源工具,主要用于测试Web应用程序。虽然 Gatling 主要专注于 HTTP 请求的性能测试,但在测试过程中,你也可以观察 DNS 解析的耗时。

在 Gatling 脚本中,你可以使用 Gatling DSL(Domain Specific Language)来模拟用户的行为。为了观察 DNS 解析的耗时,你可以使用 Gatling 提供的 exec 块,其中可以包含 Scala 代码来记录或处理 DNS 解析的相关信息。

以下是一个简单的示例 Gatling 脚本,用于执行 HTTP 请求并记录 DNS 解析耗时:

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class MyGatlingSimulation extends Simulation {

  val httpConf = http.baseUrl("http://your-website.com") // 替换为你的目标网站的URL

  val scn = scenario("MyScenario")
    .exec(http("request")
      .get("/path/to/your/resource")) // 替换为你要测试的资源路径

  setUp(
    scn.inject(atOnceUsers(1)) // 替换为你想要模拟的用户数
  ).protocols(httpConf)
}

在上述脚本中,你可以通过使用 Gatling 提供的 exec 块的 Scala 代码来记录 DNS 解析的时间。请注意,由于 Gatling 主要用于模拟用户行为,你可能需要使用一些额外的库或工具来专门分析 DNS 解析的详细信息。你可以使用类似于 dnsjava 等库,通过在 Gatling 脚本中执行相关的 Scala 代码来进行 DNS 解析的详细记录。

.exec(session => {
  val startTime = System.currentTimeMillis()
  // 执行 DNS 解析的代码,记录耗时等信息
  session
    .set("dnsResolutionTime", System.currentTimeMillis() - startTime)
})

Gatling 主要用于 HTTP 请求性能测试,对于 DNS 解析的详细分析,你可能需要结合其他工具或自定义 Scala 代码。

 

- gatling 接口范例

class GatlingUserLoadTest {
  def scn = scenario("Create Order").exec(http("Home Page Request")
    .get("/")
    .check(status.is(200))
}
setUp(scn.inject(atOnceUsers(10)).protocols(httpProtocol))

- gatling 用户密码参数化接口范例

val users = List(
  Map("username" -> "admin", "password" -> "password"),
  Map("username" -> "admin2", "password" -> "password2"),
)

val headers = Map("Content-Type" -> "application/x-www-form-urlencoded")

def login = scenario("Login").exec(http("Login Request")
  .post("/login")
  .headers(headers)
  .formParam("username", "${username}")
  .formParam("password", "${password}")
  .check(status.is(200)))

val createOrder = scenario("Create Order").exec(http("Create Order Request")
  .post("/create_order")
  .headers(headers)
  .formParam("item", "${item}")
  .check(status.is(200)))

val scn = scenario("Default").exec(login).exec(createOrder)

setUp(scn.inject(atOnceUsers(users.size)).protocols(httpProtocol))

users.foreach(user => exec(session => {
  session.set("username", user("username"))
  session.set("password", user("password"))
  session.set("item", user("item"))
}))

 

http://developer.yahoo.com/performance/

 

Exceptional Performance

Yahoo!'s Exceptional Performance team evangelizes best practices for improving web performance. They conduct research, build tools, write articles and blogs, and speak at conferences. Their best practices center around the rules for high performance web sites.

Best Practices

The Exceptional Performance team has identified a number of best practices for making web pages fast . The list includes 34 best practices divided into 7 categories.

Filter by category:

  • Content
  • Server
  • CSS
  • Javascript
  • Images
  • Mobile
  • All
  1. Make Fewer HTTP Requests
  2. Use a Content Delivery Network
  3. Add an Expires or a Cache-Control Header
  4. Gzip Components
  5. Put Stylesheets at the Top
  6. Put Scripts at the Bottom
  7. Avoid CSS Expressions
  8. Make JavaScript and CSS External
  9. Reduce DNS Lookups
  10. Minify JavaScript and CSS
  11. Avoid Redirects
  12. Remove Duplicate Scripts
  13. Configure ETags
  14. Make Ajax Cacheable
  15. Flush the Buffer Early
  16. Use GET for AJAX Requests
  17. Post-load Components
  18. Preload Components
  19. Reduce the Number of DOM Elements
  20. Split Components Across Domains
  21. Minimize the Number of iframes
  22. No 404s
  23. Reduce Cookie Size
  24. Use Cookie-free Domains for Components
  25. Minimize DOM Access
  26. Develop Smart Event Handlers
  27. Choose <link> over @import
  28. Avoid Filters
  29. Optimize Images
  30. Optimize CSS Sprites
  31. Don't Scale Images in HTML
  32. Make favicon.ico Small and Cacheable
  33. Keep Components under 25K
  34. Pack Components into a Multipart Document

 

 

 

 

end

posted @ 2009-09-21 10:42  siemens800  阅读(28)  评论(0)    收藏  举报