gpt4 book ai didi

java - 理解 jmh 中的不对称

转载 作者:行者123 更新时间:2023-12-01 09:19:33 25 4
gpt4 key购买 nike

我正在阅读有关 JMH 基准测试的内容,现在正在考虑 the example of asymmetric

他们只说了这样一句话:

So far all the tests were symmetric: the same code was executed in all the threads. At times, you need the asymmetric test.

到底在什么“时间”我需要这样的对称基准测试。我不明白该设施的任何实际用例。他们提供以下内容:

private AtomicInteger counter;

@Setup
public void up() {
counter = new AtomicInteger();
}

@Benchmark
@Group("g")
@GroupThreads(3)
public int inc() {
return counter.incrementAndGet();
}

@Benchmark
@Group("g")
@GroupThreads(1)
public int get() {
return counter.get();
}

但是你能给我一些现实世界的用例吗?我的意思是,我可能想要不对称地测量什么样的东西?

最佳答案

编程加密是一个特定的用例:

Symmetric keys simply means that the key that encrypt the data is the same key that will be decypting the data. Asymmetric keys means that the algorthm uses a different key to encrypt and decyprt the data.

In cases where performance is a valid concern, you can help minimize the performance hit from WS-Security by intelligent use of your security options. Certain web services frameworks tend to generate "all of the above" security configurations, with messages fully signed and encrypted using WS-Security and sent over SSL connections. That's fine if you really want maximum protection and don't care about performance, but in most cases it makes more sense to use either SSL (if you're only concerned about protecting the information in transit between the client and a single server) or WS-Security encryption (if you need to ship data across multiple servers while preserving confidentiality when going through the intermediaries).

You can also use WS-SecureConversation for long-running exchanges of messages between clients and a server (even one accessed through intermediaries), for a relatively modest but significant performance gain as compared to WS-Security using certificates. WS-SecureConversation works especially well in exchanges of relatively small messages where the added overhead of certificates and asymmetric encryption can be large in comparison to the actual (symmetric) encryption of the message body.

并发错误测试自动化是另一个用例:

Several different approaches have been proposed recentlyto automatically fix concurrency bugs. Theseaddress concurrency problems resulting from inadequate synchronization, including atomicity violations, deadlocks, and data races. Roughly speaking, in all of these cases the fix amounts to inserting additional synchronization to inhibit bad interleaving scenarios.

以及多核优化:

In order to optimise performance, the JVM uses a "pseudo memory barrier" in code to act as a fencing instruction when synchronizing across multiple processors. It is possible to revert back to a "true" memory barrier instruction, but this can have a noticeable (and bad) effect upon performance.

引用文献

关于java - 理解 jmh 中的不对称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40259005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com