g3bench: fix h3 target

This commit is contained in:
Zhang Jingqiang 2023-06-19 14:01:36 +08:00
parent e90c027221
commit eb7bc24678
8 changed files with 47 additions and 11 deletions

View file

@ -96,6 +96,8 @@ mime = "0.3"
percent-encoding = "2.1"
http = "0.2.9"
h2 = "0.3.19"
h3-quinn = "0.0.3"
h3 = "0.0.2"
#
log = "0.4"
slog = "2"

View file

@ -18,8 +18,8 @@ tokio = { workspace = true, features = ["rt", "net", "macros"] }
http.workspace = true
url.workspace = true
h2.workspace = true
h3 = "0.0.2"
h3-quinn = "0.0.3"
h3.workspace = true
h3-quinn.workspace = true
bytes.workspace = true
futures-util.workspace = true
tokio-openssl.workspace = true

View file

@ -29,7 +29,7 @@ use http::{HeaderValue, Method, StatusCode};
use url::Url;
use g3_types::collection::{SelectiveVec, WeightedValue};
use g3_types::net::{HttpAuth, RustlsClientConfigBuilder, UpstreamAddr};
use g3_types::net::{AlpnProtocol, HttpAuth, RustlsClientConfigBuilder, UpstreamAddr};
use super::{H3PreRequest, HttpRuntimeStats, ProcArgs};
use crate::target::{AppendRustlsArgs, RustlsTlsClientArgs};
@ -68,6 +68,7 @@ impl BenchH3Args {
let tls = RustlsTlsClientArgs {
config: Some(RustlsClientConfigBuilder::default()),
alpn_protocol: Some(AlpnProtocol::Http3),
..Default::default()
};
@ -114,7 +115,7 @@ impl BenchH3Args {
};
let mut transport = TransportConfig::default();
transport.max_concurrent_bidi_streams(VarInt::from_u32(0));
transport.max_concurrent_uni_streams(VarInt::from_u32(0));
// transport.max_concurrent_uni_streams(VarInt::from_u32(0));
// TODO add more transport settings
let mut client_config = ClientConfig::new(tls_client.driver.clone());
client_config.transport_config(Arc::new(transport));

View file

@ -129,7 +129,7 @@ impl H3TaskContext {
let mut send_stream = send_req
.send_request(req)
.await
.map_err(|e| anyhow!("failed to send request header: {e:?}"))?;
.map_err(|e| anyhow!("failed to send request header: {e}"))?;
send_stream.finish().await?;
let send_hdr_time = time_started.elapsed();
if let Some(r) = &mut self.histogram_recorder {

View file

@ -189,7 +189,7 @@ impl OpensslTlsClientArgs {
let tls_client = if let Some(p) = self.alpn_protocol {
tls_config
.build_with_alpn_protocols(Some(vec![p]))
.context("failed to build tls client with alpn protocol {p}")?
.context(format!("failed to build tls client with alpn protocol {p}"))?
} else {
tls_config.build().context("failed to build tls client")?
};

View file

@ -22,7 +22,9 @@ use anyhow::{anyhow, Context};
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command, ValueHint};
use rustls::{Certificate, PrivateKey};
use g3_types::net::{RustlsCertificatePair, RustlsClientConfig, RustlsClientConfigBuilder};
use g3_types::net::{
AlpnProtocol, RustlsCertificatePair, RustlsClientConfig, RustlsClientConfigBuilder,
};
const TLS_ARG_CA_CERT: &str = "tls-ca-cert";
const TLS_ARG_CERT: &str = "tls-cert";
@ -52,6 +54,7 @@ pub(crate) struct RustlsTlsClientArgs {
pub(crate) tls_name: Option<String>,
pub(crate) cert_pair: RustlsCertificatePair,
pub(crate) no_verify: bool,
pub(crate) alpn_protocol: Option<AlpnProtocol>,
}
impl RustlsTlsClientArgs {
@ -137,7 +140,13 @@ impl RustlsTlsClientArgs {
}
tls_config.check().context("invalid tls config")?;
let tls_client = tls_config.build().context("failed to build tls client")?;
let tls_client = if let Some(p) = self.alpn_protocol {
tls_config
.build_with_alpn_protocols(Some(vec![p]))
.context(format!("failed to build tls client with alpn protocol {p}"))?
} else {
tls_config.build().context("failed to build tls client")?
};
self.client = Some(tls_client);
Ok(())
}

View file

@ -101,9 +101,10 @@ impl FromStr for MaybeProtocol {
impl From<AlpnProtocol> for MaybeProtocol {
fn from(p: AlpnProtocol) -> Self {
match p {
AlpnProtocol::Http10 | AlpnProtocol::Http11 | AlpnProtocol::Http2 => {
MaybeProtocol::Http
}
AlpnProtocol::Http10
| AlpnProtocol::Http11
| AlpnProtocol::Http2
| AlpnProtocol::Http3 => MaybeProtocol::Http,
}
}
}
@ -117,6 +118,7 @@ pub enum Protocol {
TlsTlcp,
Http1,
Http2,
Http3,
Smtp,
SshLegacy,
Ssh,
@ -142,6 +144,7 @@ impl Protocol {
Protocol::TlsTlcp => "tls_tlcp",
Protocol::Http1 => "http_1",
Protocol::Http2 => "http_2",
Protocol::Http3 => "http_3",
Protocol::Smtp => "smtp",
Protocol::SshLegacy => "ssh_legacy",
Protocol::Ssh => "ssh",
@ -164,6 +167,7 @@ impl From<AlpnProtocol> for Protocol {
match p {
AlpnProtocol::Http10 | AlpnProtocol::Http11 => Protocol::Http1,
AlpnProtocol::Http2 => Protocol::Http2,
AlpnProtocol::Http3 => Protocol::Http3,
}
}
}

View file

@ -14,19 +14,38 @@
* limitations under the License.
*/
use std::fmt;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AlpnProtocol {
Http10,
Http11,
Http2,
Http3,
}
impl fmt::Display for AlpnProtocol {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl AlpnProtocol {
pub fn as_str(&self) -> &str {
match self {
Self::Http10 => "http/1.0",
Self::Http11 => "http/1.1",
Self::Http2 => "h2",
Self::Http3 => "h3",
}
}
pub fn wired_identification_sequence(&self) -> &'static [u8] {
match self {
Self::Http10 => b"\x08http/1.0",
Self::Http11 => b"\x08http/1.1",
Self::Http2 => b"\x02h2",
Self::Http3 => b"\x02h3",
}
}
@ -45,6 +64,7 @@ impl AlpnProtocol {
b"http/1.0" => Some(AlpnProtocol::Http10),
b"http/1.1" => Some(AlpnProtocol::Http11),
b"h2" => Some(AlpnProtocol::Http2),
b"h3" => Some(AlpnProtocol::Http3),
_ => None,
}
}