Here is the command to remove all svn folder and files in Windows:
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"
Thoughts, ideas, tips and tricks obtained from enterprise Java Application architecture and implementation.
Thursday, June 22, 2017
Monday, June 19, 2017
How Akamai CDN works?
How Akamai CDN works?
The following are the important points:
The following are the important points:
There are many great answers to this questions. But wanted to consolidate all the solutions that Akamai utilizes to try and solve the problems of the internet.
- Akamai’s Infrastructure - First thing to talk about is that the currently (as of today) Akamai has more than 2,00,000+ servers located in more than 100+ locations in the world which are very well connceted and in 90% cases, an akamai edge server is just a hop away from the end users. This kind of an infrastructure helps customers further maximise the benefits of the various solutions that Akamai offers.
- How user get into the most optimal Edge Server ? - When an end user makes a request to connect to a customer’s origin that is on Akamai. The Akamai Intelligent platform allocates an edge server to the end user (which in most cases is just a hop away) and is the request is for static content, the request is served right from the edge and if it is for a dynamic content, the edge contacts the origin and fetches the content for the end user.
- Caching - Akamai CDN like any other CDN focusses on caching of static content at the edge to enhance the internet performance. This also, provides customers an offload on their origin infrastructure. Customer’s can choose to further enhance their origin offload by using a solution called Tiered Distribution which is very simple words is all about adding a secondary layer of edge servers between the edge and the origin.
- SureRoute - For dynamic content delivery it is important that the fastest route is selected between the edge and the origin and there is a solution in place called SureRoute that works towards computing the fastest pat between the edge and the origin (i.e it works towards solving the BGP protocol problem).
- TCP Optimization - There are solutions to optimize the slow start TCP protocol and also, persistent connections are used for delivery to avoid latency that is introduced when multiple TCP connections are needed to be opened.
- Prefetching - There is another feature called Prefetching which works towards warming the cache while delivering a base HTML page to end users which means that it scans the embedded links in the base HTML page, makes request to the origin for those links and fetches them for the user while delivering the base page to the user without waiting for the user to make requests for those links. So, when users make requests for those objects they are sered right from the edge rather than from the origin, thus , enhancing performance.
- Last Mile Acceleration - There are features that work towards optimizing the last mile of the internet which is the link between the end user and the edge. In this, contents is compressed before delivering to end user. akamai can reduce size of pages, content by around 70–80% by adding compression. This largely speeds up the delivery.
There are few other solutions too on offer but the above listed ones should give anyone a broad understanding of Akamai CDN at a high level. Hope it helps :)
PaaS, SaaS and IaaS in a Picture
Here is a great picture that explains the PaaS, SaaS and IaaS.
https://venturebeat.com/2012/10/08/paas-platform-as-a-service-explained/
Sunday, June 4, 2017
Java Concurrency Topics
Issues with Collections
- ArrayIndexOutofBoundsException with syncronized collections
- fail-fast with ConcurrentModificationException
- Hidden Interators: Collector's toString, containsAll, removeAll, retrainAll methods.
Atomic variables
- AtomicBoolean
- AtomicInteger
- AtomicIntegerArray
- AtomicIntegerFieldUpdater
- AtomicLong
- AtomicLongArray
- AtomicLongFieldUpdater
- AtomicMarkableReference
- boolean compareAndSet(V expectedReference, V newReference, boolean expectedMark, boolean newMark)
- AtomicReference
- AtomicReferenceArray
- AtomicReferenceFieldUpdater
- AtomicStampedReference
- boolean compareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp)
- DoubleAccumulator
- DoubleAdder
- LongAccumulator
- LongAdder
Operations
compareAndSetgetAndSet
lazySet
addAndGet
getAndAdd
incrementAndGet
getAndIncrement
decrementAndGet
getAndDecrement
accumulateAndGet(int x, IntBinaryOperator accumulatorFunction) |
getAndUpdate(IntUnaryOperator updateFunction) |
Concurrent Collections
List Operations
addIfAbsent(E e)
compareAndSet
Map Operations
putIfAbsent
replace(K key, V oldValue, V newbvalue)
V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
V computeIfPresent(K key, BiFunction<? super K,? super V,? extendsV> remappingFunction)
V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
V computeIfPresent(K key, BiFunction<? super K,? super V,? extendsV> remappingFunction)
ConcurrentHashMap
finer-grained locking mechanism: lock striping
Weak consistent interator
size and isEmpty are just estimations
Thread States
NEW
RUNNABLE
BLOCKED
WAITING
TIMED_WAITING
- A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state.
TERMINATED
Interruptible Methods
1. The most common practice: propagating the InterruptedException. Either not catch the InterruptedException, or throwing the exception after capturing it.
2. Restoring interrupt. When a code is part of a Runnable, it is not able to throw an InterruptedException. The only choice is catching the exception, then calling the interrupt on the current thread.
Sychronizers
Examples from Java DocumentationCountDownLatch
class Driver { // ...
void main() throws InterruptedException {
CountDownLatch startSignal = new CountDownLatch(1);
CountDownLatch doneSignal = new CountDownLatch(N);
for (int i = 0; i < N; ++i) // create and start threads
new Thread(new Worker(startSignal, doneSignal)).start();
doSomethingElse(); // don't let run yet
startSignal.countDown(); // let all threads proceed
doSomethingElse();
doneSignal.await(); // wait for all to finish
}
}
class Worker implements Runnable {
private final CountDownLatch startSignal;
private final CountDownLatch doneSignal;
Worker(CountDownLatch startSignal, CountDownLatch doneSignal) {
this.startSignal = startSignal;
this.doneSignal = doneSignal;
}
public void run() {
try {
startSignal.await();
doWork();
doneSignal.countDown();
} catch (InterruptedException ex) {} // return;
}
void doWork() { ... }
}
|
Semaphore
class Pool {
private static final int MAX_AVAILABLE = 100;
private final Semaphore available = new Semaphore(MAX_AVAILABLE, true);
public Object getItem() throws InterruptedException {
available.acquire();
return getNextAvailableItem();
}
public void putItem(Object x) {
if (markAsUnused(x)) {
available.release();
}
}
// Not a particularly efficient data structure; just for demo
protected Object[] items = ... whatever kinds of items being managed
protected boolean[] used = new boolean[MAX_AVAILABLE];
protected synchronized Object getNextAvailableItem() {
for (int i = 0; i < MAX_AVAILABLE; ++i) {
if (!used[i]) {
used[i] = true;
return items[i];
}
}
return null; // not reached
}
protected synchronized boolean markAsUnused(Object item) {
for (int i = 0; i < MAX_AVAILABLE; ++i) {
if (item == items[i]) {
if (used[i]) {
used[i] = false;
return true;
} else
return false;
}
}
return false;
}
}
|
CyclicBarrier
class Solver {
final int N;
final float[][] data;
final CyclicBarrier barrier;
class Worker implements Runnable {
int myRow;
Worker(int row) { myRow = row; }
public void run() {
while (!done()) {
processRow(myRow);
try {
barrier.await();
} catch (InterruptedException ex) {
return;
} catch (BrokenBarrierException ex) {
return;
}
}
}
}
public Solver(float[][] matrix) {
data = matrix;
N = matrix.length;
Runnable barrierAction =
new Runnable() { public void run() { mergeRows(...); }};
barrier = new CyclicBarrier(N, barrierAction);
List<Thread> threads = new ArrayList<Thread>(N);
for (int i = 0; i < N; i++) {
Thread thread = new Thread(new Worker(i));
threads.add(thread);
thread.start();
}
// wait until done
for (Thread thread : threads)
thread.join();
}
}
|
Phaser
void runTasks(List<Runnable> tasks) {
final Phaser phaser = new Phaser(1); // "1" to register self
// create and start threads
for (final Runnable task : tasks) {
phaser.register();
new Thread() {
public void run() {
phaser.arriveAndAwaitAdvance(); // await all creation
task.run();
}
}.start();
}
// allow threads to start and deregister self
phaser.arriveAndDeregister();
}
void startTasks(List<Runnable> tasks, final int iterations) {
final Phaser phaser = new Phaser() {
protected boolean onAdvance(int phase, int registeredParties) {
return phase >= iterations || registeredParties == 0;
}
};
phaser.register();
for (final Runnable task : tasks) {
phaser.register();
new Thread() {
public void run() {
do {
task.run();
phaser.arriveAndAwaitAdvance();
} while (!phaser.isTerminated());
}
}.start();
}
phaser.arriveAndDeregister(); // deregister self, don't wait
}
|
Subscribe to:
Posts (Atom)