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
- Cookie
- CSS
- Javascript
- Images
- Mobile
- All
- Make Fewer HTTP Requests
- Use a Content Delivery Network
- Add an Expires or a Cache-Control Header
- Gzip Components
- Put Stylesheets at the Top
- Put Scripts at the Bottom
- Avoid CSS Expressions
- Make JavaScript and CSS External
- Reduce DNS Lookups
- Minify JavaScript and CSS
- Avoid Redirects
- Remove Duplicate Scripts
- Configure ETags
- Make Ajax Cacheable
- Flush the Buffer Early
- Use GET for AJAX Requests
- Post-load Components
- Preload Components
- Reduce the Number of DOM Elements
- Split Components Across Domains
- Minimize the Number of iframes
- No 404s
- Reduce Cookie Size
- Use Cookie-free Domains for Components
- Minimize DOM Access
- Develop Smart Event Handlers
- Choose <link> over @import
- Avoid Filters
- Optimize Images
- Optimize CSS Sprites
- Don't Scale Images in HTML
- Make favicon.ico Small and Cacheable
- Keep Components under 25K
- Pack Components into a Multipart Document
end

浙公网安备 33010602011771号