parallel-counter-app increments an Integer column in mysql table Number atomically.
Assumption:-Count Reads are not as frequents as writes.
Write :- Keep count local(AtomicLong) to each app and update to databse periodically. This approach reduces overhead of thread thread synchronization and increases app performance reducing load on database at the same time. It consistently updates counter even if deployed on distributed servers because once update command is fired to mysql it updates counter atomically(row level locking).
Read :- Count can be read from Database directly.
Limitation:- Some count might be lost in case of app crash. e.g if we are updating the in memory count to table every 10 seconds and the app crashes , counts of at most 10 seconds will be lost.
Solutions:- Reduce the update frequency Fire each update count request to database instead of local count
Use Redis server and use its atomic increment feature to updated the count consistently. More scalable,distributed, consistent and fault tolerant than approach 1;
Faster Simultaneous reads/writes.
[VM1,VM2,VM3..VMn] --------each increment event-----> KAFKA ---------> Flink{accumulate count}-----------------> Sink [Redis/Mysql/Cassandra]
- Java 8
- Maven 3
- Mysql
- clone the app from github.
- Go to extracted app directory.
- Provide mysql connection url, user password properties in
/src/main/resources/application.properties
- Build application using command
mvn clean install
. - Run App using command
mvn spring-boot run
- go to apache jmeter bin folder and run below command to run the test
- To modify the jmx file open it in jmeter GUI and change.
- Run jmeter test using command line e.g [ D:\work\personal\parallel-counter-app\parallel-counter-app\CounterApi.jmx -l ApiTestReport1.jtl]
- Stop app using ctrl+c
- Run another cycle if needed.
Note 1:- App creates a new table named Number on each startup (drops older one if exists). Note 2:- make sure app is shut down properly before another run. Note 3:- I ran the test using 10000 users with ramp up period of 10 seconds, the count in table was 10000 (subject to jmeter finished with 0% error).