์์ ๋ฅผ ํตํด ARCUS java client ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ์ ์์๋ณธ๋ค. ์๋ ์์ ๋ ARCUS cache์ key๊ฐ โsample:testKeyโ์ด๊ณ value๊ฐ โtestValueโ์ธ cache item์ ์ ์ฅํ๋ค.
package com.navercorp.arcus.example;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import net.spy.memcached.ArcusClient;
import net.spy.memcached.ConnectionFactoryBuilder;
public class HelloArcus {
private static final String ARCUS_ADMIN = "10.0.0.1:2181,10.0.0.2:2181,10.0.0.3:2181";
private static final String SERVICE_CODE = "test";
private final ArcusClient arcusClient;
public static void main(String[] args) {
HelloArcus hello = new HelloArcus();
System.out.printf("hello.setTest() result=%b", hello.setTest());
hello.closeArcusConnection();
}
public HelloArcus() {
arcusClient = ArcusClient.createArcusClient(ARCUS_ADMIN, SERVICE_CODE,
new ConnectionFactoryBuilder()); // (1)
}
public boolean setTest() {
Future<Boolean> future = null;
try {
future = arcusClient.set("sample:testKey", 10, "testValue"); // (2)
} catch (IllegalStateException e) {
// client operation queue ๋ฌธ์ ๋ก ์์ฒญ์ด ๋ฑ๋ก๋์ง ์์์ ๋ ์์ธ์ฒ๋ฆฌ.
}
if (future == null) return false;
try {
return future.get(500L, TimeUnit.MILLISECONDS); // (3)
} catch (TimeoutException te) { // (4)
future.cancel(true);
} catch (ExecutionException re) { // (5)
future.cancel(true);
} catch (InterruptedException ie) { // (6)
future.cancel(true);
}
return false;
}
public void closeArcusConnection() {
arcusClient.shutdown(); // (7)
}
} (1) ArcusClient ํด๋์ค์ ๊ฐ์ฒด(client ๊ฐ์ฒด)๋ฅผ ์์ฑํ๋ค. Client ๊ฐ์ฒด๋ ๋งค ์์ฒญ๋ง๋ค ์์ฑํ์ง ์๊ณ ๋ฏธ๋ฆฌ ํ๋๋ฅผ ๋ง๋ค์ด ์ฌํ์ฉํ๋๋ก ํ๋ค. ARCUS์ ์ ์ํ ๋, ๊ฐ์ข ์ค์ ์ ๋ณ๊ฒฝํ๊ธฐ ์ํด์ ConnectionFactoryBuilder๋ฅผ ์ฌ์ฉํ์๋ค.
- ์๋ชป๋ SERVICE_CODE๋ฅผ ์ง์ ํ๋ค๋ฉด NotExistsServiceCodeException์ด ๋ฐ์ํ๋ค.
- SERVICE_CODE๋ ์ฌ๋ฐ๋ฅด์ง๋ง ์ ์ ๊ฐ๋ฅํ cache ์๋ฒ(๋๋ ๋ ธ๋)๊ฐ ์๋ค๋ฉด, ๋ชจ๋ ์์ฒญ์ Exception์ ๋ฐ์์ํจ๋ค. Cache ์๋ฒ๊ฐ ๊ตฌ๋๋์ด ์ ์์ด ๊ฐ๋ฅํด์ง๋ฉด, ์๋์ผ๋ก ํด๋น cache ์๋ฒ๋ก ์ฐ๊ฒฐํ์ฌ ์ ์ ์๋น์คํ๊ฒ ๋๋ค.
(2) Client ๊ฐ์ฒด์ set ๋ฉ์๋๋ฅผ ํธ์ถํ๊ณ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ Boolean ๊ฐ์ ๊ฐ๋ Future ํด๋์ค์ ๊ฐ์ฒด(future ๊ฐ์ฒด)๋ก ๋ฐ๋๋ค.
- ์ ์ฅํ ๊ฐ์ผ๋ก ""(๊ธธ์ด๊ฐ 0์ธ ๋ฌธ์์ด)์ ๋ฃ์ผ๋ฉด, ""์ด ๊ทธ๋๋ก ์ ์ฅ๋๋ค. (ํด๋น key๊ฐ ์ญ์ ๋์ง ์๋๋ค.)
- ์ ์ฅํ ๊ฐ์ผ๋ก null์ ์ง์ ํ ์ ์๋ค. (key ์ญ์ ์๋์ด๋ฉด,
delete๋ฉ์๋๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค.) - ์ ์ฅํ ๊ฐ์ serializableํด์ผ ํ๋ค. (์ฌ์ฉ์ ์ ์ ํด๋์ค์ ๊ฒฝ์ฐ Serializable ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํด์ผ ํ๋ค.)
(3) Future ๊ฐ์ฒด์ ๊ฐ์ ๋ฐ์์ result์ ๋ด๋๋ค. (๋ง์ฝ set ์์ ์ด ์คํจํ์์ ๊ฒฝ์ฐ์๋ false๊ฐ ๋ฐํ๋๋ค.)
- Cache ์๋ฒ์ key๊ฐ ์กด์ฌํ์ง ์๋๋ค๋ฉด, ๋ค์ ๋งํด cache miss์ด๋ผ๋ฉด, null์ด ๋ฐํ๋๋ค.
- ๊ธธ์ด๊ฐ 0์ธ ๋ฌธ์์ด(โโ)์ cache miss๊ฐ ์๋๊ณ โโ๊ฐ ์ ์ฅ๋์ด ์๋ ๊ฒ์ด๋ค.
(4) ์ง์ ํ ์๊ฐ์ ๊ฒฐ๊ณผ๊ฐ ๋์ด ์ค์ง ์๊ฑฐ๋ JVM์ ๊ณผ๋ถํ๋ก operation queue์์ ์ฒ๋ฆฌ๋์ง ์์ ๊ฒฝ์ฐ TimeoutException์ด ๋ฐ์ํ๋ค.
- ์๋ฅผ ๋ค์ด, timeout ์๊ฐ์ 500ms๋ก ์ง์ ํ๋๋ฐ GC time์ด 600ms๊ฑธ๋ ธ๋ค๋ฉด ARCUS cache ์๋ฒ์ ํต์ ์ ๋ฌธ์ ๊ฐ ์์์๋ ๋ถ๊ตฌํ๊ณ 100ms๋ฅผ ์ด๊ณผํ๊ธฐ ๋๋ฌธ์ TimeoutException์ด ๋ฐ์ํ๊ฒ ๋๋ค.
- TimeoutException์ด ์ฐ์ํด์ n(๋ํดํธ๋ 10)ํ ์ด์ ๋ฐ์ํ๋ฉด ํด๋ผ์ด์ธํธ๋ ์๋ฒ์์ ์ฐ๊ฒฐ์ ๋๊ณ ์ฌ์ ์ํ๋ค. ์ฌ๊ธฐ์์ n๋ฒ์ ๊ฐ์ ConnectionFactoryBuilder๋ฅผ ์์ฑํ ๋ ์ง์ ํ ์ ์๋ค.
- ๋ํ, ๋ชจ๋ Exception์ด ๋ฐ์ํ ์ํฉ์์๋ future.cancel(true)๋ฅผ ๋ฐ๋์ ํธ์ถํด ์ฃผ์ด์ผ ํ๋ค.
(5) ArcusClient์ operation queue์ ๋๊ธฐํ๊ณ ์๋ ์์ ์ด ์ทจ์๋์์ ๋, ExecutionException์ด ๋ฐ์ํ๋ค. ExecutionException์ ์๋ฒ ๋๋ ๋คํธ์ํฌ ์ฅ์ ์ ๋ฐ์ํ๋ค.
(6) ๋ค๋ฅธ ์ฐ๋ ๋์์ ํด๋น ์ฐ๋ ๋์ ์์ ์ Interruptํ์ ๋ InterruptedException์ด ๋ฐ์ํ๋ค. (๋ฐ์ํ ์ฌ์ง๊ฐ ๊ฑฐ์ ์๋ค.)
(7) ํ๋ก์ธ์ค๋ฅผ ์ข
๋ฃํ๊ธฐ ์ ์ ๋ ์ด์ ArcusClient๋ฅผ ์ฌ์ฉํ์ง ์์ผ๋ฏ๋ก,
๋ฐ๋์ shutdown ๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ์๋ฒ์์ ์ฐ๊ฒฐ์ ๋์ด์ผ ํ๋ค.
- Tomcat๊ณผ ๊ฐ์ WAS์์๋ Tomcat์ด shutdown์ด ๋ ๋
shutdown๋ฉ์๋๊ฐ ํธ์ถ๋๊ฒ ํ๋ฉด ๋๋ค. - Spring container์์ ๊ด๋ฆฌ๋๋ ๊ฒฝ์ฐ bean ์ค์ ์ destroy-method์์
shutdown๋ฉ์๋๊ฐ ํธ์ถ๋๋๋ก ์ค์ ํด์ผ ํ๋ค.
ํ๋์ ARCUS Client ๊ฐ์ฒด๋ ARCUS cache cloud์ ์๋ ๋ชจ๋ cache server(or cache node)์ ์ฐ๊ฒฐ์ ํ๋์ฉ ์์ฑํ๋ฉฐ, ์์ฒญ๋๋ ๊ฐ cache item์ key์ ๋ํด ๊ทธ key๊ฐ mapping๋๋ cache server์์ ์ฐ๊ฒฐ์ ์ด์ฉํ์ฌ request๋ฅผ ๋ณด๋ด๊ณ response๋ฅผ ๋ฐ๋๋ค.
ARCUS Client ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ผ๋ก ๋ ๊ฐ์ง๊ฐ ์๋ค.
- ๋จ์ผ ARCUS Client ์์ฑ
- ARCUS Client Pool ์์ฑ
๋จผ์ , ๋จ์ผ ARCUS Client ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ธฐ ์ํ ๋ฉ์๋๋ ์๋์ ๊ฐ๋ค.
ArcusClient.createArcusClient(String arcusAdminAddress, String serviceCode, ConnectionFactoryBuilder cfb)- arcusAdminAddress: ์ ๊ทผํ cache cloud๋ฅผ ๊ด๋ฆฌํ๋ ARCUS zookeeper ensemble ์ฃผ์
- IP:port ๋ฆฌ์คํธ์ธ "ip1:port,ip2:port,ip3:port" ํํ๋ก ์ง์ ํ๊ฑฐ๋
- "FQDN:port" ํํ๋ก ์ง์ ํ ์ ์๋ค. (zookeeper IP list์ ๋ํ domain name์ DNS์ ๋ฑ๋กํ ๊ฒฝ์ฐ)
- serviceCode: ์ ์ํ cache cloud์ ์๋ณ์
- cfb: ARCUS client์ ๋์ ์ค์ ์ ์ํ ConnectionFactoryBuilder ๊ฐ์ฒด
ARCUS_ADMIN ์๋ฒ์์ ๊ด๋ฆฌ๋๋ SERVICE_CODE์ ํด๋นํ๋ cache cloud๋ก ์ฐ๊ฒฐํ๋ ํ๋์ ArcusClient ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ ์๋ ์๋์ ๊ฐ๋ค.
ConnectionFactoryBuilder cfb = new ConnectionFactoryBuilder();
ArcusClient client = ArcusClient.createArcusClient(ARCUS_ADMIN, SERVICE_CODE, cfb);ํ๋์ ARCUS Client๋ง์ผ๋ก๋ ์์ฉ์ requests๋ฅผ ์ฒ๋ฆฌํ๋ ์ฉ๋ ์ฆ, throughput์ ํ๊ณ๊ฐ ์๋ค. ์๋ฅผ ๋ค์ด, ํ๋์ ์ฐ๊ฒฐ์ ํตํด ํ๋์ request๊ฐ ์ฒ๋ฆฌ๋๋ ์๊ฐ์ด 1ms๋ผ ๊ฐ์ ํ๋ฉด, ๊ทธ ์ฐ๊ฒฐ์ ํตํด ์ต๋ 1000 requests/second ๋ฐ์ ์ฒ๋ฆฌํ ์ ์๋ค. ๋ฐ๋ผ์, ๋ง์ ์์ฒญ ์ฒ๋ฆฌ๋์ด ํ์ํ ์์ฉ์ธ ๊ฒฝ์ฐ๋ ๋ค์์ ARCUS client ๊ฐ์ฒด๋ฅผ ์์ฑํ์ฌ์ผ ํ๋ค. ์ด๋ฅผ ์ํด ARCUS client pool ๊ฐ์ฒด๋ฅผ ์์ฑํ ์ ์์ผ๋ฉฐ, ์๋์ ๋ฉ์๋๋ฅผ ์ฌ์ฉํด ์์ฑํ๋ค.
ArcusClient.createArcusClientPool(String arcusAdminAddress, String serviceCode, ConnectionFactoryBuilder cfb, int poolSize);๋ฉ์๋์ ์ธ์๋ก ๋จ์ผ ARCUS client ๊ฐ์ฒด๋ฅผ ์์ฑํ ์์ ์ธ์๋ค ์ธ์ pool์ ๋ค์ด๊ฐ arcus client ๊ฐ์ฒด ์๋ฅผ ์ง์ ํ๋ poolSize ์ธ์๊ฐ ์๋ค. pool size๊ฐ ๋๋ฌด ์์ผ๋ฉด ์์ฉ ์์ฒญ๋ค์ ์ ์๊ฐ์ ์ฒ๋ฆฌํ ์ ์๋ ๋ฌธ์ ๊ฐ ์๊ธฐ๊ณ , ๋๋ฌด ํฌ๋ฉด arcus cache server๋ก ๋ถํ์ํ๊ฒ ๋ง์ ์ฐ๊ฒฐ์ ๋งบ๊ฒ ํ๋ค. ์ ์ ํ pool size๋ "์์ฉ ์๋ฒ์ peak arcus request ์์ฒญ๋"์ "ํ๋์ arcus client์ ์ฒ๋ฆฌ๋"์ผ๋ก ๋๋๋ฉด ์ป์ ์ ์๋ค. ์ฌ๊ธฐ์, ํ๋์ arcus client๊ฐ ์ฒ๋ฆฌํ ์ ์๋ ์ฒ๋ฆฌ๋์ ์์ฉ ์๋ฒ๊ฐ ์์ฒญํ๋ arcus request ์ ํ๊ณผ ์์ฉ ์๋ฒ์ cache server ๊ฐ์ ๋คํธ์ ์ํ ๋ฑ์ ์ํฅ๋ฐ์ ์ ์์ผ๋ฏ๋ก, ์ค์ ํ ์คํธ๋ฅผ ํตํด ํ์ธํด ๋ณด๊ณ pool size๋ฅผ ๊ฒฐ์ ํ๊ธธ ๊ถํ๋ค.
ํน์ SERVICE_CODE์ ํด๋นํ๋ cache cloud๋ก ์ฐ๊ฒฐ๋๋ ARCUS client 4 ๊ฐ๋ฅผ ๊ฐ์ง๋ pool์ ์์ฑํ๋ ์๋ ๋ค์๊ณผ ๊ฐ๋ค.
int poolSize = 4;
ConnectionFactoryBuilder cfb = new ConnectionFactoryBuilder();
ArcusClientPool pool = ArcusClient.createArcusClientPool(ARCUS_ADMIN, SERVICE_CODE, cfb, poolSize);ARCUS client ๊ฐ์ฒด๋ฅผ ์ ์์ ์ผ๋ก ์์ฑํ๋ฉด, ์๋์ ๋ก๊ทธ์ ๊ฐ์ด cache cloud์ ์ ์ ์ฐ๊ฒฐ๋จ์ ๋ณผ ์ ์๋ค.
WARN net.spy.memcached.CacheManager: All arcus connections are established.
ARCUS cache cloud๋ก ์ ์ ์ฐ๊ฒฐ๋์ง ์์ผ๋ฉด, ๋ค์๊ณผ ๊ฐ์ ๋ก๊ทธ๊ฐ ๋ณด์ธ๋ค. ์๋ฅผ ๋ค์ด 5๋์ Cache server์ ์ ์์ ํด์ผ ํ๋๋ฐ ์ด๋ค ์ค ์ผ๋ถ ์๋ฒ์ ์ ์ํ์ง ๋ชปํ๋ค๋ฉด ์๋ ๋ก๊ทธ๊ฐ ๋จ๊ฒ ๋๋ค. ์ ์ ์คํจํ cache server์ ๋ํด์๋ ARCUS client๊ฐ 1์ด์ ํ ๋ฒ์ฉ ์๋์ผ๋ก ์ฌ์ฐ๊ฒฐ์ ์๋ํ๋ค.
WARN net.spy.memcached.CacheManager: Some arcus connections are not established.
ArcusClient ๋๋ ArcusClientPool๋ฅผ ์ฌ์ฉํ๊ณ ๋ ๋ค์์๋ ๋ฐ๋์ shutdown() ๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ client์ admin, cache server๊ฐ์ ์ฐ๊ฒฐ์ ํด์ ์์ผ์ฃผ์ด์ผ ํ๋ค.
client.shutdown();
pool.shutdown();Arcus์ ๋ํ ๋งค ์์ฒญ๋ง๋ค arcus client ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ ์๋ฉธ์ํค๋ ๊ฒ์ ์ ์ ํ์ง ๋ชปํ๋ค. ์์ฉ ์๋ฒ์ ๊ตฌ๋ ์์ arcus client ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ , ์ข ๋ฃ ์์ arcus client ๊ฐ์ฒด๋ฅผ ์๋ฉธํ๋ฉด ๋๋ค.
์ผ๋ฐ์ ์ผ๋ก, ์์ฉ์์๋ ArcusClient wrapper๋ฅผ ๋ง๋ค์ด ์ฌ์ฉํ ๊ฒ์ ๊ถ์ฅํ๋ค. ์ด๋ ๊ฒ ํ๋ฉด ArcusClient์ ์๋ช ์ฃผ๊ธฐ๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์์ํด์ง๋ค. Service code๋ณ ArcusClient instance๋ฅผ ๊ฐ์ง๋ factory๋ฅผ singleton์ผ๋ก ๋ง๋ค์ด๋๊ณ WAS๊ฐ ์ด๊ธฐํ ๋ ๋ Arcus server ์ ์ฐ๊ฒฐ์ ๋งบ๋๋ก ํ์. WAS๊ฐ shutdown๋ ๋ ArcusClient๋ ํจ๊ป shutdown๋๋๋ก ์ค์ ํ๋ฉด ๊ฐ์ฅ ์ด์์ ์ด๋ค.
ARCUS๋ cache server list๋ฅผ ์๋์ผ๋ก ๊ด๋ฆฌํ๋ค. Cache server๋ค ์ค์ ์ผ๋ถ ์๋ฒ๊ฐ ์ฌ์ฉ ๋ถ๊ฐ๋ฅํ ์ํ๊ฐ ๋๋ฉด ARCUS admin์ด ์๋์ผ๋ก ์ํฉ์ ์ธ์งํ๊ณ ํด๋น ์๋ฒ๋ฅผ cache server list์์ ์ ๊ฑฐํ๋ฉฐ, ๋ณ๊ฒฝ๋ cache server list๊ฐ ์์์ ๊ฐ arcus client์ ์๋ฆผ์ผ๋ก์จ ๊ฐ arcus client๊ฐ ์ต์ ์ cache server list๋ฅผ ์ ์งํ๊ฒ ํ๋ค. ๋ฐ๋๋ก ์ฌ์ฉ ๊ฐ๋ฅํ cache server๊ฐ ์ถ๊ฐ๋์์ ๋์๋ ๋ง์ฐฌ๊ฐ์ง๋ก, ARCUS admin์ ๋์์ผ๋ก ARCUS client๋ ์ต์ ์ cache server list๋ฅผ ์ ์งํ๊ณ , cache key์ cache server์์ mapping์ ๊ฐฑ์ ํ๊ฒ ํ๋ค. ๋ฐ๋ผ์, ARCUS client๋ฅผ ์ฌ์ฉํ ๋ cache server ๋์์ ๋ณํ์ ๋ํ ๋ฐฉ์ด ๋ก์ง์ ์ ๊ฒฝ ์ฐ์ง ์์๋ ๋๋ค.
ARCUS client๋ key-value item์ ๋ฐ์ดํฐ ์์ถ ๋ฐ ํด์ ๊ธฐ๋ฅ์ ๊ฐ์ง๊ณ ์๋ค. ์ฆ, ์ผ์ ํฌ๊ธฐ ์ด์์ ๋ฐ์ดํฐ์ด๋ฉด ๊ทธ ๋ฐ์ดํฐ๋ฅผ ์์ถํ์ฌ cache server์ ๋ณด๋ด์ด ์ ์ฅํ๊ณ , cache server๋ก ๋ถํฐ ๊ฐ์ ธ์จ ๋ฐ์ดํฐ๊ฐ ์์ถ ๋ฐ์ดํฐ์ด๋ฉด, ํด์ ํ์ฌ ์์ฉ์ ์ ๋ฌํ๋ค.
ARCUS client๋ ์ ์ ํ ๊ฐ์ ํฌ๊ธฐ๊ฐ 16KB ์ด์์ผ ๊ฒฝ์ฐ์ ์์ถํ์ฌ cache server์ ์ ์ฅํ๋๋ก ๋์ด ์๋ค. ์ด๋ฌํ ๋ฐ์ดํฐ ์์ถ ์๊ณ๊ฐ์ ConnectionFactoryBuilder์ setTranscoder๋ฉ์๋๋ฅผ ํตํด ์ค์ ํ ์ ์๋ค.
๋ค์์ 4KB ์ด์์ ๋ฐ์ดํฐ๋ ๋ชจ๋ ์์ถํ๋๋ก ์ค์ ํ๋ ์์ ์ด๋ค.
ConnectionFactoryBuilder cfb = new ConnectionFactoryBuilder();
SerializingTranscoder trans = new SerializingTranscoder();
trans.setCharset(โUTF-8โ);
trans.setCompressionThreshold(4096);
cfb.setTranscoder(trans);
ArcusClient client = ArcusClient.createArcusClient(SERVICE_CODE, cfb);ARCUS client ์ฌ์ฉ ์์ default(DefaultLogger), log4j(Log4JLogger), slf4j(SLF4JLogger), jdk(SunLogger) ๋ฑ 4๊ฐ์ง ์ข ๋ฅ์ Logger๋ฅผ ์ฌ์ฉํ ์ ์๋ค. ์ฌ์ฉํ logger๋ฅผ ์ง์ ํ์ง ์์ผ๋ฉด ArcusClient๋ DefaultLogger๋ฅผ ๊ธฐ๋ณธ์ผ๋ก ์ฌ์ฉํ๋ฉฐ, DefaultLogger๋ INFO level ์ด์์ ๋ก๊ทธ๋ฅผ stderr (System.err) ๋ก ์ถ๋ ฅํ๋ค. (๋ณ๊ฒฝ ๋ถ๊ฐ)
log4j๋ฅผ ์ฌ์ฉํ์ฌ ArcusClient ๋ก๊ทธ๋ฅผ ๊ด๋ฆฌํ๋ ค๋ฉด, ์๋ ์ต์ ์ WAS๋ ์๋ฐ ํ๋ก์ธ์ค ์ต์ ์ ์ถ๊ฐํ์ฌ JVM ๊ตฌ๋์ System property๋ฅผ ์ง์ ํ๋ค.
-Dnet.spy.log.LoggerImpl=net.spy.memcached.compat.log.Log4JLogger
๋๋, ์์ค ์ฝ๋์์ ArcusClient / ArcusClientPool์ ์ฌ์ฉํ๊ธฐ ์ ์ ์ง์ System property๋ฅผ ์ค์ ํ์ฌ ์ฌ์ฉํ ์ ์๋ค. (programmatic configuration)
System.setProperty("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.Log4JLogger");
...
ConnectionFactoryBuilder cfb = new ConnectionFactoryBuilder();
ArcusClient client = ArcusClient.createArcusClient(SERVICE_CODE, cfb);ARCUS Java client์์๋ Log๋ฅผ ๊ธฐ๋กํ ๋ Class์ ์ด๋ฆ(clazz.getName())์ ๊ธฐ์ค์ผ๋ก Logger๋ฅผ ๊ตฌ๋ถํ์ฌ ์ฌ์ฉํ๋ฉฐ,
class์ ์ด๋ฆ๊ณผ ์ ํํ ์ผ์นํ๋ ๋ก๊ฑฐ๊ฐ ์๋ค๋ฉด logger tree ์์ ์์ logger ๋ฅผ ์ฌ์ฉํ๋ค.
์๋์ ์์ ๋ root logger ์ level์ WARN์ผ๋ก ์ค์ ํ์ฌ WARN level ์ด์์ ๋ก๊ทธ๋ ํญ์ ๊ธฐ๋กํ๊ณ , net.spy.memcached.protocol.ascii.CollectionUpdateOperationImpl class์ ๋ก๊ทธ๋ง DEBUG level ์ด์์ ๋ก๊ทธ๋ฅผ ๊ธฐ๋กํ๋๋ก ํ ์์ ์ด๋ค.
<Root level="WARN">
<AppenderRef ref="console" />
</Root>
<Logger name="net.spy.memcached.protocol.ascii.CollectionUpdateOperationImpl" additivity="false" level="DEBUG">
<AppenderRef ref="console" />
</Logger>Application์ ๋๋ฒ๊น ํด์ผ ํ ๋ ARCUS client์์ Arcus server๋ก ์ ์กํ๋ ascii protocol ๋ฌธ์์ด์ด ๊ถ๊ธํ ๋๊ฐ ์๋ค. ARCUS Java Client์์ ARCUS server๋ก ์ ์กํ๋ protocol์ ๋ก๊ทธ๋ก ์ดํด๋ณด๋ ค๋ฉด ์๋์ ๊ฐ์ด logger๋ฅผ ์ค์ ํ๋ฉด ๋๋ค. ์์ ์ ๋์ด๋ logger๋ฅผ ๋ชจ๋ ์ค์ ํ๋ฉด ์์ฒญ(get, set ๋ฑ..)๋ณ๋ก ๋ชจ๋ ๋ก๊ทธ๊ฐ ๋จ๊ฒ ๋๋ ํ์ํ ์์ฒญ์ ํด๋นํ๋ logger๋ง ์ค์ ํ๋ฉด ํธ๋ฆฌํ๋ค. Ascii Protocol์ ๋ํ ์์ธํ ๋ด์ฉ์ ARCUS ์๋ฒ ๋ช ๋ น ํ๋กํ ์ฝ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ๊ธฐ ๋ฐ๋๋ค.
<!-- collection update -->
<Logger name="net.spy.memcached.protocol.ascii.CollectionUpdateOperationImpl" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<!-- collection piped exist -->
<Logger name="net.spy.memcached.protocol.ascii.CollectionPipedExistOperationImpl" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<!-- set attributes -->
<Logger name="net.spy.memcached.protocol.ascii.SetAttrOperationImpl" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<!-- collection insert -->
<Logger name="net.spy.memcached.protocol.ascii.CollectionInsertOperationImpl" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<!-- collection get -->
<Logger name="net.spy.memcached.protocol.ascii.CollectionGetOperationImpl" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<!-- collection update -->
<Logger name="net.spy.memcached.protocol.ascii.CollectionUpdateOperationImpl" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>
<!-- collection count -->
<Logger name="net.spy.memcached.protocol.ascii.CollectionCountOperationImpl" level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Logger>๊ธฐํ log4j์ ์์ธํ ์ค์ ๋ฐฉ๋ฒ์ log4j ์ค์ ๋ฐฉ๋ฒ์ ํ์ธํ๊ธฐ ๋ฐ๋๋ค.
log4j 1.2 ์ดํ ๋ฒ์ ์์ ๋ณด์ ์ทจ์ฝ์ ์ด ์กด์ฌํ์ฌ, ARCUS client์ 1.11.5 ๋ฒ์ ๋ถํฐ Log4JLogger๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด log4j2 ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์๊ตฌ๋๋ค. ์ด๋ฅผ ์ํด ์์ฉ ์์กด์ฑ์ ์๋์ ๊ฐ์ด log4j2 ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ถ๊ฐํ๋ค.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.2</version>
</dependency>๋ง์ฝ ์๋์ ๊ฐ์ ์์ธ๊ฐ ๋ฐ์๋๋ฉด, log4j2 ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ํด๋์คํจ์ค์ ์กด์ฌํ์ง ์์ ๊ฒ์ด๋ค. log4j2 ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์์ฉ ์์กด์ฑ์ ์ ๋๋ก ์ถ๊ฐ๊ฐ ๋๋์ง ํ์ธํ๋๋ก ํ๋ค.
Warning: net.spy.memcached.compat.log.Log4JLogger not found while initializing net.spy.compat.log.LoggerFactory
java.lang.NoClassDefFoundError: org/apache/logging/log4j/spi/ExtendedLogger
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at net.spy.memcached.compat.log.LoggerFactory.getConstructor(LoggerFactory.java:134)
at net.spy.memcached.compat.log.LoggerFactory.getNewInstance(LoggerFactory.java:119)
at net.spy.memcached.compat.log.LoggerFactory.internalGetLogger(LoggerFactory.java:100)
at net.spy.memcached.compat.log.LoggerFactory.getLogger(LoggerFactory.java:89)
at net.spy.memcached.ArcusClient.<clinit>(ArcusClient.java:183)
at Main.main(Main.java:10)
slf4j๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ, ARCUS client์ SLF4JLogger ํด๋์ค๋ฅผ ์ฌ์ฉํ ๊ฒ์ด๋ค. ์ด ํด๋์ค๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด slf4j๋ฅผ ๊ตฌํํ ๋ก๊น ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์์ฉ ์์กด์ฑ์ ์ถ๊ฐ๋์ด์ผ ํ๋ค. ๋ง์ฝ ์ถ๊ฐํ์ง ์์ ๊ฒฝ์ฐ ์๋์ ์์ธ ๋ฉ์์ง๊ฐ ๋ฐ์ํ๋ค.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
log4j, logback๊ณผ ๊ฐ์ ๋ํ์ ์ธ ์๋ฐ์ ๋ก๊ทธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ slf4j api๋ฅผ ๊ตฌํํ ๊ตฌํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ ๊ณตํ๊ณ ์๋ค. ํด๋น ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ ์๋์ ๊ฐ์ด ์์ฉ ์์กด์ฑ์ ์ถ๊ฐํ๋๋ก ํ๋ค. ์์ธํ ๋ด์ฉ์ slf4j ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ๋ค.
<!-- slf4j + log4j ์ฌ์ฉ์ -->
<dependency>
<groupId>com.navercorp.arcus</groupId>
<artifactId>arcus-java-client</artifactId>
<version>${arcus-java-client.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency><!-- slf4j + logback ์ฌ์ฉ์ -->
<dependency>
<groupId>com.navercorp.arcus</groupId>
<artifactId>arcus-java-client</artifactId>
<version>${arcus-java-client.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>๋ํ 2๊ฐ ์ด์์ slf4j์ ๊ตฌํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(log4j-slf4j-impl, logback-classic, ...)๋ค์ด ๊ฐ์ ํด๋์คํจ์ค์ ์กด์ฌํ ๊ฒฝ์ฐ, SLF4J์์ multiple binding error๊ฐ ๋ฐ์ํ๋ฏ๋ก ๋ฐ๋์ exclusion ํค์๋๋ฅผ ์ด์ฉํด slf4j ๊ตฌํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ํ๋๋ง ์กด์ฌํ๋๋ก ํ์ฌ์ผ ํ๋ค.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
ARCUS๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์๊ฒฉ Cache ์์คํ ์ด๋ฏ๋ก ์์ฒญ์ ๋ํ ์๋ต์ ๋ฐ์ ๋๋ง๋ค ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ฒดํํด์ผ ํ๋ ๋จ์ ์ด ์๋ค. ์ด๋ ๊ฒฐ๊ตญ JVM์ Garbage Collector์ ๋ถ๋ด์ผ๋ก ์์ฉํ ๊ฒ์ด๋ค. ๋ฐ๋ผ์ ๋ง์ฝ ์ค์ ๋ฐ์ดํฐ๊ฐ ๊ฑฐ์ ๋ณ๊ฒฝ๋์ง ์๊ณ , ๋ณ๊ฒฝ์ด ์๋๋ผ๋ ์์ฃผ ์งง์ ์๊ฐ ๋ด์๋ ์ด์ ๋ฐ์ดํฐ๋ฅผ ๋ณด์ฌ์ค๋ ์๊ด์๋ ๊ฒฝ์ฐ๋ผ๋ฉด Front Cache๋ฅผ ์ฌ์ฉํ ๊ฒ์ ๊ณ ๋ คํด ๋ณผ ๋ง ํ๋ค.
Front cache๋ฅผ ์ด์ฉํ๋ ค๋ฉด Remote Cache์์ Hit๊ฐ ๋์์ ๊ฒฝ์ฐ ๋ณ๋๋ก Front Cache ์ ์ฅ์์ ๊ธฐ๋ก์ ํด ์ฃผ์ด์ผ ํ๋๋ฐ, ์ฝ๋๊ฐ ์๋นํ ์ง์ ๋ถํด ์ง๋ ๊ฒฝํฅ์ด ์๋ค. ๊ทธ๋ฆฌ๊ณ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ๋๋ ์๋ ๊ทธ๋ฆผ์ ๋์จ ๊ฒ์ฒ๋ผ ์ ์ผ ๋จผ์ Front Cache๋ฅผ ํ์ธํ๊ณ ๋ค์์ Remote Cache๋ฅผ ํ์ธํ๋ค๋ฉด ์ด ๋ํ ํ๋ก๊ทธ๋จ์ด ๋ณต์กํด์ ธ ๋ฒ๋ฆฐ๋ค.
๋ฐ๋ผ์ Transparentํ๊ฒ ์ฆ, ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์์์ Front Cache๋ฅผ ํ์ฑํํ์ฌ JVM์์ ์ผ์ ์๊ฐ Item์ ๋ณด๊ดํด ์ค ์ ์๋ค๋ฉด ํธ๋ฆฌํ๋ฉด์๋ ๋ณด๋ค ๋น ๋ฅธ ์์ฉ์ ๊ฐ๋ฐํ ์ ์์ ๊ฒ์ด๋ค. ARCUS์๋ Ehcache๋ผ๋ Local cache ํ๋ฌ๊ทธ์ธ์ด ์ถ๊ฐ๋์ด ๋ณต์กํ ํ๋ก๊ทธ๋จ ์์ ์์ด ๋ฐ๋ก Front cache๋ฅผ ์ฌ์ฉํ ์ ์๋๋ก ๋์ด ์๋ค. ์ฌ์ฉ์๋ ๊ฐ๋จํ ์ต์ ๋ง ์ค์ ํ๋ฉด 2๋ฒ๊ณผ 3๋ฒ ์์ ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ด์์ ์๋์ผ๋ก ์ํํ๋ค.
๋ค์์ Front cache๋ฅผ ์ฌ์ฉ์ ์ํ ๋ฉ์๋๋ก ConnectionFactoryBuilder ํด๋์ค๋ฅผ ์์ฑํ ๋ ์ ์ฉํ๋ค.
-
setMaxFrontCacheElements(int to)(Required)์ฌ๊ธฐ์ ์ ์ฉ๋๋ ๊ฐ์ Front Cache์์ ์ฌ์ฉํ ์ต๋ Item์๋ฅผ ์๋ฏธํ๋ค. ๊ธฐ๋ณธ๊ฐ์ 0์ธ๋ฐ, 0์ด๋ฉด Front Cache๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค๋ ๋ป์ด๋ค. ๋ฐ๋ผ์ Front Cache๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ ๋ฐ๋์ ์์ ์ ์๊ฐ์ ์ง์ ํด์ผ ํ๋ค. ๋ง์ฝ ์ต๋ Item ์๋ฅผ ์ด๊ณผํ๋ฉด LRU ์๊ณ ๋ฆฌ์ฆ์ ํตํด ๊ฐ์ฅ ์ฌ์ฉ๋์ง ์๋ Item์ ์ ๊ฑฐํ๊ณ ์๋ก์ด Item์ ๋ฑ๋กํ๊ฒ ๋๋ค.
-
setFrontCacheExpireTime(int to)(Optional, default 5)Front Cache item์ expire time์ด๋ค. Front cache๋ item๋ณ expire time์ ์ค์ ํ์ง ์๊ณ , ๋ฑ๋ก๋ ๋ชจ๋ item์ ๋์ผํ expire time์ด ์ ์ฉ๋๋ค. ๊ธฐ๋ณธ๊ฐ์ 5์ด๋ฉฐ ๋จ์๋ second์ด๋ค. ์ค์ ํ์ง ์๋๋ค๋ฉด ๊ธฐ๋ณธ๊ฐ์ ๊ทธ๋๋ก ์ฌ์ฉํ๋ค๋ฉด ๋ฑ๋ก๋ ์ง 5์ด๊ฐ ์ง๋๋ฉด ์๋์ผ๋ก ์ฌ๋ผ์ง๊ฒ ๋๋ค.
-
setFrontCacheCopyOnRead(boolean copyOnRead)(Optional, default false)Front Cache ์์ Copy Cache ๊ธฐ๋ฅ์ copy on read ์ต์ ์ ํ์ฑํ์ํค๊ธฐ ์ํ ์ค์ ์ด๋ฉฐ, ๊ธฐ๋ณธ๊ฐ์ false ์ด๋ค.
-
setFrontCacheCopyOnWrite(boolean copyOnWrite)(Optional, default false)Front Cache ์์ Copy Cache ๊ธฐ๋ฅ์ copy on write ์ต์ ์ ํ์ฑํ์ํค๊ธฐ ์ํ ์ค์ ์ด๋ฉฐ, ๊ธฐ๋ณธ๊ฐ์ false ์ด๋ค.
EhCache ์ Copy Cache ๊ธฐ๋ฅ์ ๋ํด์๋ ๋ค์ ๋ฌธ์๋ฅผ ์ฐธ์กฐ ๋ฐ๋.
Front cache ์ฌ์ฉ ์์ ์ฃผ์ ์ฌํญ์ ๋ค์๊ณผ ๊ฐ๋ค.
- Transparent Front Cache๋ ํ์ฌ Key-Value get/set์ ๋ํด์๋ง ์ ์ฉ ๊ฐ๋ฅํ๋ค.
- Front cache๋ remote ARCUS์ sync๋ฅผ ๋ง์ถ์ง ์๊ธฐ ๋๋ฌธ์ ์ฃผ๋ก read-only data๋ฅผ cachingํ๋๋ฐ ์ ํฉํ๋ค. ๊ทธ๋ฆฌ๊ณ front caching expire time๋ remote cache entry update์ฃผ๊ธฐ์ ๋ฐ๋ผ sync๊ฐ ๋ง์ง ์๋ ๊ธฐ๊ฐ์ ์ ํ์ ํ์ฌ ์ค์ ํด์ผ ํ๋ค.
- Front Cache ๋ฐ์ดํฐ๋ flush ๋ช ๋ น์ด๋ฅผ ํตํด์ flush ๋์ง ์๋๋ค
์๋๋ Front cache๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํ ์ฝ๋์ด๋ค. setMaxFrontCacheElements๋ง 0๋ณด๋ค ํฐ ๊ฐ์ผ๋ก ์ค์ ํ๋ฉด Front Cache๊ฐ ํ์ฑํ๋๋ค. (setFrontCacheExpireTime ๋ ์ฌ์ฉ ์ฉ๋์ ๋ง๋๋ก ๋ช ์์ ์ธ ๊ฐ์ ์ค์ ํด ์ฃผ๋ ๊ฒ์ ์ถ์ฒํจ)
ConnectionFactoryBuilder factory = new ConnectionFactoryBuilder();
/* Required to use transparent front cache */
factory.setMaxFrontCacheElements(10000);
/* Optional settings */
factory.setFrontCacheExpireTime(5);
factory.setFrontCacheCopyOnRead(true);
factory.setFrontCacheCopyOnRead(true);
ArcusClient client = new ArcusClient(SERVICE_CODE, factory);์์ฉ์์ ARCUS์ ๋ํด front cache๋ฅผ ์ฌ์ฉํด์ผ ๋ถ๋ถ๊ณผ ์ฌ์ฉํ์ง ์์์ผ ํ๋ ๋ถ๋ถ์ผ๋ก ๊ตฌ๋ถ๋๋ค๋ฉด, ๊ฐ ์ฉ๋์ ๋ง๋ ARCUS client ๊ฐ์ฒด๋ฅผ ๋ณ๋๋ก ์์ฑํ์ฌ ์ฌ์ฉํ์ฌ์ผ ํ๋ค.
-
setFailureMode(FailureMode fm)
FailureMode๋ฅผ ๋ณ๊ฒฝํ๋ค. Cancel, Redistrubute, Retry์ 3๊ฐ FailureMode๊ฐ ์์ผ๋ฉฐ, ๊ฐ๊ฐ์ ์๋ฏธ๋ ๋ค์๊ณผ ๊ฐ๋ค.
- Cancel : ๋ค์ด(down)๋ ๋ ธ๋์ ์์ฒญํ๋ ๋ชจ๋ ์์ ์ ์๋์ผ๋ก ์ทจ์ํ๋ค.
- Redistribute : ์ฌ๋ฌ ๊ฐ์ Node๊ฐ ๋ฑ๋ก๋์ด ์์ ๊ฒฝ์ฐ, Request๊ฐ ์คํจํ๋ฉด ๋ค์ Node์๊ฒ ํด๋น Request๋ฅผ ๋ค์ ์์ฒญํ๋ค. ์ด๋ ๊ฒ ํด์ Timeout์ด ๋ ๋๊น์ง ์ํํ๋ค. ๋ง์ฝ Node๊ฐ ํ ๊ฐ๋ผ๋ฉด ๋ค์ Node๋ ์๊ธฐ ์์ ์ด ๋๋ค.
- Retry : Timeout์ด ๋ ๋๊น์ง Request๊ฐ ์คํจํ๋ฉด ๊ณ์ ํ์ฌ Node์ ์์ฒญ์ ์๋ํ๋ค
ARCUS๋ Cancel ๋ชจ๋๋ฅผ ๋ํดํธ๋ก ์ฌ์ฉํ๋ค. Redistribute๋ Retry๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ, ๋ฐ๋ณต์ ์ธ ์์ฒญ์ ์ํด ์์ฉ ์๋ฒ์ ๋ถํ๊ฐ ๋ฐ์ํ ์ ์์ด ์ด๋ฌํ ๋ ๊ฐ์ง ๋ฐฉ์์ ์ฌ์ฉ์ ๊ธ์งํ๊ณ ์๋ค.
-
setOpTimeout(long t)
SpyThread๊ฐ ARCUS Cache Server๋ก๋ถํฐ ์๋ต์ ๋ฐ๋ ๋์์ ์คํผ๋ ์ด์ ํ์์์์ ๋ฐ๋ฆฌ์ด ๋จ์๋ก ์ค์ ํ๋ค. ๊ธฐ๋ณธ๊ฐ์ 1,000 ๋ฐ๋ฆฌ์ด์ด๋ค. ์ฐธ๊ณ ๋ก, ์์ฉ์ด Callback์ ๋ฐ์ ๋๊น์ง ์ค์ ํ๋ Timeout์ โ์คํผ๋ ์ด์ ํ์์์ + ๋ช ๋ น์ด ์์ฑ์๊ฐ + ๋ช ๋ น์ด ๋ฑ๋ก์๊ฐโ์ ํฌํจํ๋ Timeout์ผ๋ก ์ด๊ฒ๊ณผ๋ ๋ค๋ฅด๋ค.
-
setProtocol(ConnectionFactoryBuilder.Protocol prot)
ARCUS client์ server ์ฌ์ด์ ์ฌ์ฉํ ํ๋กํ ์ฝ์ ์ง์ ํ๋ค. Text์ Binary์ ๋ ํ๋กํ ์ฝ์ด ์์ผ๋, ARCUS์์๋ Text ํ๋กํ ์ฝ๋ง์ ์ฌ์ฉํด์ผ ํ๋ค.
-
setMaxReconnectDelay(long to)
ARCUS์ ์ฐ๊ฒฐ์ด ๋๊ฒผ์ ๊ฒฝ์ฐ ๋ค์ ์ฐ๊ฒฐ์ ๋งบ๊ธฐ ์ํด์ ๋๊ธฐํ๋ ์ต๋ ์๊ฐ์ ์ด ๋จ์๋ก ์ง์ ํ๋ค. ARCUS๋ ๊ธฐ๋ณธ 1์ด๋ฅผ ์ฌ์ฉํ๋ค.
-
setOpQueueFactory(OperationQueueFactory q)
๋ช ๋ น์ด์ ๋ด์ฉ์ ๋ด๋ operation ํ๋ฅผ ์์ฑํ๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ํฌ๊ธฐ๊ฐ 16,384์ธ ํ๋ฅผ ์ฌ์ฉํ๋ค. ํ์ ํฌ๊ธฐ๋ฅผ 1000์ผ๋ก ๋ณ๊ฒฝํ๊ณ ์ถ๋ค๋ฉด setOpQueueFactory(new ArrayOperationQueueFactory(1000))์ผ๋ก ์ค์ ํ๋ฉด ๋๋ค.
-
setTranscoder(Transcoder t)
์บ์์ ๋ฐ์ดํฐ ์์ญ์ ๋ํ character set๊ณผ ์์ถ ๊ธฐ์ค์ ์ค์ ํ๋ค. GZip ์์ถ์ ์ฌ์ฉํ๋ฉฐ, ๊ธฐ๋ณธ๊ฐ์ UTF-8๊ณผ 16,384 byte์ด๋ค. ์ฆ, ๋ชจ๋ ์์ฒญ์ data ์์ญ์ UTF-8๋ก encoding/decoding ๋๊ณ data ์์ญ์ ํฌ๊ธฐ๊ฐ 16,384byte ์ด์์ด๋ฉด ์์ถํ์ฌ ARCUS์ ํต์ ํ๊ฒ ๋๋ค.
๋ง์ฝ, character set์ EUC-KR๋ก ์ค์ ํ๊ณ ์์ถ ๊ธฐ์ค์ 4,096byte๋ก ๋ณ๊ฒฝํ๋ ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์ค์ ํ๋ค.
SerializingTranscoder trans = new SerializingTranscoder(); trans.setCharset(โEUC-KRโ); trans.setCompressionThreshold(4096); setTranscoder(trans);
-
setShouldOptimize(boolean o)
์ต์ ํ ๋ก์ง ์ฌ์ฉ์ฌ๋ถ๋ฅผ ๊ฒฐ์ ํ๋ค. ์ต์ ํ ๋ก์ง์ Operation Queue์ ์์๋๋ก ์๋ get ์ฐ์ฐ๋ค์ multi-get๊ณผ get ์ฐ์ฐ์ผ๋ก ์กฐํฉํ์ผ๋ก ํ๊บผ๋ฒ์ ์ํํ๊ฒ ๋๋ค. ARCUS์์๋ optimize ๋ก์ง ์ฌ์ฉ์ ๊ถ์ฅํ์ง ์๋๋ค.
-
setReadBufferSize(int to)
ARCUS server socket๊ณผ ํต์ ํ ๋ ์ฌ์ฉ๋๋ ์ ์ญ ByteBuffer ํฌ๊ธฐ๋ฅผ ์ค์ ํ๋ค. (์ด๋ฆ์ Read์ด์ง๋ง ์ฝ๊ธฐ/์ฐ๊ธฐ ๋ฒํผ์ ํฌ๊ธฐ๋ ์ด ๊ฐ์ ๋ฐ๋ฅธ๋ค) ๋ง์ฝ ByteBuffer ํฌ๊ธฐ๋ฅผ ๋์ด์๋ ๋ฐ์ดํฐ๊ฐ ๋์ด์ค๋ฉด ์ฌ ์ฌ์ฉ์ฑ์ ๋์ด๊ธฐ ์ํด ByteBuffer ํฌ๊ธฐ๋งํผ ์ฒ๋ฆฌํ ํ ByteBuffer์ ๋ด์ฉ์ ๋น์ฐ๊ณ , ๋ค์ ์ฌ์ฉํ๋๋ก ๋์ด ์๋ค. ํฌ๊ธฐ์ ๋จ์๋ byte์ด๋ฉฐ, ๊ธฐ๋ณธ๊ฐ์ 16,384์ด๋ค.
-
setDaemon(boolean d)
๊ธฐ๋ณธ๊ฐ์ด true์ด๋ค.
-
setTimeoutExceptionThreshold(int to)
Timeout์ด ์ฐ์์ผ๋ก ๋ฐ์ํ ๊ฒฝ์ฐ ํด๋น Connection์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค๊ณ ํ๋จํ์ฌ Connection์ ๋๊ณ ์ฌ์ ์์ ์๋ํ๋ค. ARCUS์์ ์ฌ์ฉํ๋ ์ฐ์ Timeout ํ๊ณ๊ฐ์ 10์ด๋ค.
-
setTimeoutRatioThreshold(int to)
Client request๊ฐ ์ด๋ค ์ด์ ๋ก ์ค๋ซ๋์ ์ฒ๋ฆฌ๋์ง ๋ชปํ๋ฉด, ARCUS client๋ continuous timeout ๋ฐฉ๋ฒ์ผ๋ก ์ด๋ฅผ ํ์งํ๊ณ ์์ฉ์๊ฒ ๋น ๋ฅธ ์คํจ ์๋ต์ ์ ๋ฌํ๋ค. ๋ฐ๋ผ์, ์์ฉ์ ์คํจํ request ์ฑ๊ฒฉ์ ๋ฐ๋ผ DB ์กฐํํ ์ง ์๋๋ฉด ARCUS์ ์ฌ์์ฒญํ ์ง๋ฅผ ๊ฒฐ์ ํ์ฌ ์์ง์ผ ์ ์๋ค.
Client request๊ฐ ์ค๋ซ๋์ ์ฒ๋ฆฌ๋์ง ๋ชปํ๋ ๊ฒ์ด ์๋ ๊ทธ ์ฒ๋ฆฌ ์๋๊ฐ ๋งค์ฐ ๋๋ ค์ง ๊ฒฝ์ฐ์๋ ์ผ๋ถ request์ ๋ํด operation timeout์ด ๋ฐ์ํ์ง๋ง ๋ค๋ฅธ ์ผ๋ถ requests๋ ์ ์ ์ฒ๋ฆฌ๋ ์ ์๋ค. ์ด ๊ฒฝ์ฐ, client request๊ฐ ์ ์ ์ฒ๋ฆฌ๋ ์์ง๋ง continuous timeout์ด ๋ฐ์ํ์ง ์์ ์ ์๋ค. ์ด๋ฌํ ์ํ๋ฅผ ํ์งํ๊ธฐ ์ํ์ฌ, ์ต๊ทผ 100๊ฐ requests์ ๋ํด timeout ratio๋ฅผ ๊ณ์ฐํ์ฌ ํน์ threshold ์ด์์ด๋ฉด ํ์ฌ connection์ ๋๊ณ ์ฌ์ ์์ ์๋ํ๋ ๊ธฐ๋ฅ์ด๋ค.
Timeout ratio threshold์ default ๊ฐ์ 0์ผ๋ก disabled๋ ์ํ์ด๋ฉฐ, 1 ~ 99 ์ฌ์ด์ ๊ฐ์ ์ฃผ๋ฉด ๊ทธ ๊ฐ์ผ๋ก timeout ratio threshold๊ฐ ์ค์ ๋์ด ๋์ํ๊ฒ ๋๋ค.
-
setOpQueueMaxBlockTime(long t)
Operation์ ์์ฒญํ ๋ ๋น๋๊ธฐ์์ผ๋ก Operation queue์ ๋ฑ๋กํ์ฌ ์์ ์ ์์ฒญํ๊ฒ ๋์ด ์๋๋ฐ, ์ด ์ต์ ์ Queue๊ฐ ๋ชจ๋ ๊ฝ ์ฐฌ ์ํ๊ฐ ๋์์ ๋ ์ต๋ ๊ธฐ๋ค๋ฆฌ๋ ์๊ฐ์ ์๋ฏธํ๋ค. ๋จ์๋ millisecond ์ด๊ณ , ๊ธฐ๋ณธ๊ฐ์ 10000ms์ด๋ค.
