gpt4 book ai didi

java - 慢查询在带有多线程的Aerospike中集成

转载 作者:行者123 更新时间:2023-12-03 12:59:22 28 4
gpt4 key购买 nike

我们正在创建一个Java客户端以将数据直接写入Aerospike的内存中,并创建另一个Java客户端以从内存中读取数据。
两个客户端都是多线程的。

在我们的读取客户端内部,有一些queryAggregate操作是在UDF中实现的。

我们面临的问题如下:

如果我们仅为写入操作分配1个线程,为读取操作分配2个线程,则我们有〜25K TPS可供读取。

如果我们为写操作分配2个线程,而为读操作分配相同数量的线程,那么我们只有不到10K的TPS可供读取。

Aerospike服务器在具有24个物理CPU内核的计算机上运行。写入和读取客户端都在此计算机上同时运行。
该服务器几乎只在运行Aerospike服务器。 CPU资源是完全免费的。

以下是我们当前的Aerospike服务器配置:

paxos-single-replica-limit=1;pidfile=null;proto-fd-max=15000;advertise-ipv6=false;auto-pin=none;batch-threads=4;batch-max-buffers-per-queue=255;batch-max-requests=5000;batch-max-unused-buffers=256;batch-priority=200;batch-index-threads=24;clock-skew-max-ms=1000;cluster-name=null;enable-benchmarks-fabric=false;enable-benchmarks-svc=false;enable-hist-info=false;hist-track-back=300;hist-track-slice=10;hist-track-thresholds=null;info-threads=16;log-local-time=false;migrate-max-num-incoming=4;migrate-threads=1;min-cluster-size=1;node-id-interface=null;nsup-delete-sleep=100;nsup-period=120;nsup-startup-evict=true;proto-fd-idle-ms=60000;proto-slow-netio-sleep-ms=1;query-batch-size=100;query-buf-size=2097152;query-bufpool-size=256;query-in-transaction-thread=false;query-long-q-max-size=500;query-microbenchmark=false;query-pre-reserve-partitions=false;query-priority=10;query-priority-sleep-us=1;query-rec-count-bound=18446744073709551615;query-req-in-query-thread=false;query-req-max-inflight=100;query-short-q-max-size=500;query-threads=6;query-threshold=10;query-untracked-time-ms=1000;query-worker-threads=15;run-as-daemon=true;scan-max-active=100;scan-max-done=100;scan-max-udf-transactions=32;scan-threads=4;service-threads=24;sindex-builder-threads=4;sindex-gc-max-rate=50000;sindex-gc-period=10;ticker-interval=10;transaction-max-ms=1000;transaction-pending-limit=20;transaction-queues=4;transaction-retry-ms=1002;transaction-threads-per-queue=4;work-directory=/opt/aerospike;debug-allocations=none;fabric-dump-msgs=false;max-msgs-per-type=-1;prole-extra-ttl=0;service.port=3000;service.address=any;service.access-port=0;service.alternate-access-port=0;service.tls-port=0;service.tls-access-port=0;service.tls-alternate-access-port=0;service.tls-name=null;heartbeat.mode=multicast;heartbeat.multicast-group=239.1.99.222;heartbeat.port=9918;heartbeat.interval=150;heartbeat.timeout=10;heartbeat.mtu=1500;heartbeat.protocol=v3;fabric.port=3001;fabric.tls-port=0;fabric.tls-name=null;fabric.channel-bulk-fds=2;fabric.channel-bulk-recv-threads=4;fabric.channel-ctrl-fds=1;fabric.channel-ctrl-recv-threads=4;fabric.channel-meta-fds=1;fabric.channel-meta-recv-threads=4;fabric.channel-rw-fds=8;fabric.channel-rw-recv-threads=16;fabric.keepalive-enabled=true;fabric.keepalive-intvl=1;fabric.keepalive-probes=10;fabric.keepalive-time=1;fabric.latency-max-ms=5;fabric.recv-rearm-threshold=1024;fabric.send-threads=8;info.port=3003;enable-security=false;privilege-refresh-period=300;report-authentication-sinks=0;report-data-op-sinks=0;report-sys-admin-sinks=0;report-user-admin-sinks=0;report-violation-sinks=0;syslog-local=-1


以下是aerospike.conf文件:

# Aerospike database configuration file for use with systemd.

service {
paxos-single-replica-limit 1 # Number of nodes where the replica count is automatically reduced to 1.
proto-fd-max 15000
}

logging {
console {
context any info
}
}

network {
service {
address any
port 3000
}

heartbeat {
mode multicast
multicast-group 239.1.99.222
port 9918

# To use unicast-mesh heartbeats, remove the 3 lines above, and see
# aerospike_mesh.conf for alternative.

interval 150
timeout 10
}

fabric {
port 3001
}

info {
port 3003
}
}

namespace test {
replication-factor 2
memory-size 4G
default-ttl 30d # 30 days, use 0 to never expire/evict.

storage-engine memory
}

namespace bar {
replication-factor 2
memory-size 4G
default-ttl 30d # 30 days, use 0 to never expire/evict.

storage-engine memory

# To use file storage backing, comment out the line above and use the
# following lines instead.
# storage-engine device {
# file /opt/aerospike/data/bar.dat
# filesize 16G
# data-in-memory true # Store data in memory in addition to file.
# }
}


有人可以告诉我们当前的瓶颈在哪里吗?
增加写入线程数时如何提高读取速度?

上面的配置是默认配置,我们还没有做任何更改。

最佳答案

我不确定您在说什么:

第一件事,我不知道用1个线程或2个线程阅读意味着什么。您说的是使用2个AerospikeClient实例。它们是分散在不同的客户端计算机上,还是都在同一实例上?

接下来,Java客户端是多线程的(不是您编写的1个线程或2个线程)。如果您使用的是同步客户端,则每个操作都将在线程中运行并等待响应。请在Aerospike网站上查看introduction to the Java client

您的Aerospike集群只是一个节点吗?它不能仅使用一个节点执行复制因子2。

谓词过滤与基于UDF的逻辑

无论您在流UDF的过滤器中执行什么逻辑,都应尝试将其移至predicate filtering。在Java客户端中,这是在PredExp class中实现的(请参见examples)。

配置调整

您正在执行写入和查询,没有单记录读取或批量读取。您应该调低批处理索引线程,并调高查询线程。

您有两个配置相同的内存命名空间。同时杀死foobar,让我们定义另一个:

service {
paxos-single-replica-limit 1 # Number of nodes where the replica count is automatically reduced to 1.
proto-fd-max 15000
batch-index-threads 2 # you don't need 24 batch threads, you're not using them
query-threads 24 # setting it to #cpu
query-in-transaction-thread true # because you query an in-memory namespace
query-priority 40
# auto-pin cpu # uncomment this if you have kernel >= 3.19
}

logging {
console {
context any info
}
}

network {
service {
address any
port 3000
}

heartbeat {
mode multicast
multicast-group 239.1.99.222
port 9918

# To use unicast-mesh heartbeats, remove the 3 lines above, and see
# aerospike_mesh.conf for alternative.

interval 150
timeout 10
}

fabric {
port 3001
}

info {
port 3003
}
}

namespace demo {
replication-factor 2
memory-size 10G
partition-tree-sprigs 4096 # maximize these for in-memory, you have plenty of DRAM
default-ttl 30d

storage-engine memory
}

我相信你应该
  • 减少批处理索引线程( batch-index-threads )的数量
  • 将每个CPU核心 query-threads 的数量增加到一个
  • 提高 query-priority
  • 因为您正在使用内存中的命名空间,所以我将 query-in-transaction-thread config参数设置为true
  • 最大化 partition-tree-sprigs 。我建议您应该使用 auto-pin cpu

  • 请参阅: What's New In Aerospike 3.12What's New in Aerospike 3.13 & 3.14

    还有什么?

    根据您通过调整后的配置获得的结果,这仍有待观察。稍后,您需要找出系统中有多少个对象,以及它们的平均对象大小是用于容量规划的。

    关于java - 慢查询在带有多线程的Aerospike中集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46642515/

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