New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
may_http
耗时不符合预期
#92
Comments
处理 import com.alibaba.fastjson.JSON
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
@RestController
class TestController {
@GetMapping("/rust")
fun rust(@RequestParam(defaultValue = "rust") param: String?): String? {
try {
//模拟耗时操作
Thread.sleep(1000)
} catch (e: InterruptedException) {
e.printStackTrace()
}
val map = HashMap<String, String?>()
map["param"] = param
return JSON.toJSONString(map)
}
} |
你的逻辑就是一个一个的请求啊,没有任何并发操作 for i in 0..10 {
let uri = uri.clone();
let start = current_time_millis();
let mut rsp = client.get(uri)?;
let end1 = current_time_millis();
rsp.read_to_string(&mut s)?;
let end2 = current_time_millis();
println!("{} get response={}, request cost{}ms read cost{}ms",
i, s, end1 - start, end2 - end1);
s.clear();
} |
如果要并行请求,直接用 |
可以用 |
好的,感谢。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
发起10次http请求,耗时是10+s,而不是1+s。这是我的toml:
以下是发起请求的代码:
下面是控制台输出的结果:
可以看到,使用
may_http
发起10
次请求,总共耗时10+ s
,如果用go语言
编写相同的逻辑,耗时在1.1s
以内,因此这里到底是may
有问题,还是may_http
有问题?@Xudong-HuangThe text was updated successfully, but these errors were encountered: