Kotlin corutines是有限状态机和一些任务运行器的糖(例如,默认的ForkJoinPool).https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md#implementation-details
换句话说,java/kotlin运行时中还没有运行时协同程序(但这可以随http://cr.openjdk.java.net/~rpressler/loom/Loom-Proposal.html而改变).Kotlin协程只是连续执行的任务,它们是逐个执行的.每个任务都可以在线程池的任何线程中执行.
Go运行时支持"协同程序".但是goroutines并不是真正的协同程序.Goroutines不允许在程序中设置屈服点.此外,Go不允许设置自定义线程池.您只能在默认池中设置线程大小.
kotlin协同程序和goroutine之间的第一个区别是Go运行时管理此时正在运行的协同程序.当goroutine在某些IO操作(或同步原语)被阻塞时,请选择下一个Job来执行它.在JVM中,没有这种术语的智能工作转换.
因此,Go可以廉价地改变当前正在运行的工作.Go只需改变一些注册表https://groups.google.com/forum/#!msg/golang-nuts/j51G7ieoKh4/wxNaKkFEfvcJ.但也有人说,JVM可以使用堆栈线程而不是使用寄存器.因此根本没有保存和加载寄存器.
kotlin协程和goroutines之间的第二个区别是协同程序的类型.Kotlin协同程序是无堆栈协程.Goroutines是堆栈协程.Kotlin协程的所有状态都存储在Kotlin上下文中,该上下文存储在堆中.Goroutines状态存储在寄存器和线程堆栈中.
我想知道,哪些协程(goroutines和kotlin协程)在IO绑定任务中更快?CPU绑定任务?内存消耗怎么样?
我有一些节点。每个节点都属于其他网络。每个节点都有像192.168.0.2这样的私有 IP,并保持在 NAT 之后。
是否有可能在节点之间进行通信?实际上,我需要在这些独立节点之间传输文件。
我尝试使用这个项目 - https://github.com/libp2p/go-libp2p。但是libp2p有一些限制:
但是我有具有私有 IP 地址的节点,它们属于不同的网络。
更新。
有这样的解决方案:
因此,让我们考虑一个通用Spring boot应用程序,它用于JOOQ数据库数据库访问和Flyway数据库迁移。该项目用于gradle依赖管理。
我想要以下东西:
gradle build。因此,我们看到任务执行的顺序错误。如果我理解正确的话,Amazon Aurora 有异步只读副本。所以,我们可以得到一些读取延迟(看起来,延迟大约是100 ms)。
我需要同步读取副本。那么,我可以为 Amazon Aurora for PostgreSQL 设置这种类型的复制吗?
database-replication amazon-web-services amazon-rds amazon-aurora
我为与 Cassandra 一起使用的 Spring Boot 应用程序开发了集成测试。我CassandraTemplate用于与 Cassandra 通信。
我对数据库src/test/resources/application.properties有以下配置:
spring.data.cassandra.contact-points=cassandra-host
spring.data.cassandra.port=9042
Run Code Online (Sandbox Code Playgroud)
要Testcontainers使用 Cassandra创建,我尝试了两种方法:
1) https://niels.nu/blog/2017/spring-cassandra-integration-tests.html
@ActiveProfiles("test")
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@SpringBootTest(classes = {ExampleApplication.class})
@ContextConfiguration(initializers = CounterIntegrationTestContainers.Initializer.class)
@EnableConfigurationProperties
public class CounterIntegrationTestContainers extends CounterIntegrationTest {
@ClassRule
public static GenericContainer cassandra =
new GenericContainer("cassandra:3")
.withExposedPorts(9042);
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
EnvironmentTestUtils.addEnvironment(
"testcontainers",
configurableApplicationContext.getEnvironment(),
"cassandra.host=" + cassandra.getContainerIpAddress(),
"cassandra.port=" + cassandra.getMappedPort(9042)
);
}
}
}
Run Code Online (Sandbox Code Playgroud)
2) https://www.baeldung.com/spring-boot-testcontainers-integration-test - 在本例中我们可以看到 postgresql 容器,但我将其更改为 Cassandra:
public …Run Code Online (Sandbox Code Playgroud) cassandra spring-boot spring-data-cassandra spring-boot-test testcontainers
有一个Dijkstra的算法.我想给生成图形|E|和|V|,其中的算法执行松弛的最大数量alt ? dist[u] + length(u, v).
这是一个ACM problem.但我不知道如何解决它.我期待着任何想法.
Example.让|V| = 4与|E| = 3.比,我正在寻找具有以下边缘和重量(v1, v2, w)的图表:
(1, 2, 0)
(1, 3, 1)
(1, 4, 2)
我正在开发一个简单的聊天。我真的很喜欢基于 Tomcat 的 spring websocket API,但是有一个问题。Tomcat 使用基于线程的模型。如果我有大约 500 个在线用户,tomcat 会启动 200 个线程(默认值)并且我的 CPU 会死掉。因此,我需要一个基于事件循环的 websocket 实现。我决定尝试使用 websockets 的全新 spring 反应式 API。
所以,我需要与聊天室聊天。当某个用户在聊天室内发送消息时,必须发送给该聊天室内的所有用户。
Spring 提供以下 API:
@Service
public class ChatWebSocketHandler implements WebSocketHandler {
@Override
public Mono<Void> handle(WebSocketSession session) {
Mono<Void> input = ;
Mono<Void> output = ;
return Mono.zip(input, output).then();
}
}
Run Code Online (Sandbox Code Playgroud)
没有用于检测connected和disconnected事件的API (就像 Tomcat 一样)。因此,我无法存储active sessions可用于消息广播的 集合。
java spring reactive-programming spring-websocket spring-webflux
我有两个服务。服务 A 像这样调用服务 B:
HttpGet request = new HttpGet("http://127.0.0.1:8083/getTest");
HttpResponse httpResponse = httpClient.execute(request);
Run Code Online (Sandbox Code Playgroud)
我有错误:
There was an unexpected error (type=Internal Server Error, status=500).
Connect to 127.0.0.1:8083 [/127.0.0.1] failed: Connection refused: connect
Run Code Online (Sandbox Code Playgroud)
这是docker ps 输出:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a8eaf08881a service_A "./gradlew bootRun" 5 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp service_A
b7436a77e438 service_B "go-wrapper run" About an hour ago Up 4 seconds 0.0.0.0:8083->8083/tcp service_B
Run Code Online (Sandbox Code Playgroud)
我创建了docker网络:
docker network create webproxy
Run Code Online (Sandbox Code Playgroud)
我的 …
我有一台安装了PostgreSQL的服务器.我的所有服务都在容器中工作(docker-compose).我想从容器中使用我的Host PostgreSQL.买我有错误:
Unable to obtain Jdbc connection from DataSource (jdbc:postgresql://localhost:5432/shop-bd) for user 'shop-bd-user': Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL State : 08001
Error Code : 0
Message : Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster …Run Code Online (Sandbox Code Playgroud) 我有简单的程序:
#include <iostream>
using namespace std;
int main()
{
int a = 5;
int b = 6;
int* p1 = &a;
int* p2 = &b;
std::cout << p1 << " " << p2 << " ,sizeof(int)=" << sizeof(int) << std::endl;
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它产生以下输出:
00DBF9B8 00DBF9AC ,sizeof(int)=4
Run Code Online (Sandbox Code Playgroud)
但是,00DBF9B8 - 00DBF9AC == ?.我无法理解这个结果.
如果我像这样修改程序:
#include <iostream>
using namespace std;
int main()
{
static int a = 5;
static int b = 6;
int* p1 = &a;
int* p2 …Run Code Online (Sandbox Code Playgroud) 目前,Kotlin 协程的实现无需 JVM 的帮助。它不使用绿色(虚拟)线程之类的东西。您可以在此处阅读有关协程实现的信息 - https://github.com/Kotlin/KEEP/blob/master/proposals/coroutines.md#implementation-details
在不久的将来(比如1-2年),Loom项目(JVM中绿色线程的实现)将会发布。您可以在这里阅读有关它的详细信息 - http://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part1.html
那么,Kotlin 会使用这些虚拟线程作为编译后端吗?或者有什么原因,为什么不能呢?我谈论了所需版本的 JVM 目标(很明显,我们需要自己的 Android 实现)。
实际上,还有一个更普遍的问题。当 Project Loom 发布时,我们真的需要 Kotlin 协程吗?