B4J Tutorial [Server] Performance measures

B4J server library is based on an open source project named Jetty.
Jetty server performance is excellent which means that B4J server performance is also excellent.

The following numbers are the result of a simple test where one program sends many requests to the server program. Both running on the same computer.

The actual numbers are not very important and should not be taken too seriously. The main point is that a B4J server can easily handle huge traffic.

The numbers were measured in Release mode.
  • Simple handler that writes some text as the response: >2000 requests per second.
  • Handler that connects to a local MySQL database (wamp installation) and issues a SELECT query (using ConnectionPool): >2000 requests per second
  • Same handler in single threaded mode: ~1300 requests per second
  • Handler that issues an INSERT command to the MySQL database: ~180 requests per second
  • Same handler in single threaded mode: ~35 requests per second
 

warwound

Expert
Licensed User
Longtime User
Very impressive.
Were the benchmarks done on a particularly hi-spec computer or just a 'standard' spec computer?

Martin.
 

luke2012

Well-Known Member
Licensed User
Longtime User
I agree with @warwound.
Impressive performance on a pc with MySQL DB.
What about the "Data Collection Solution" with a SQLite DB as reported in your Tutorial ?
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
The test was done with a SQLite database with a single table. The table has two columns and 10000 rows:
B4X:
sql1.InitializeSQLite(File.DirApp, "1.db", True)
sql1.ExecNonQuery("PRAGMA journal_mode = wal")
DBUtils.CreateTable(sql1, "table1", _
   CreateMap("col1": DBUtils.DB_INTEGER, "col2": DBUtils.DB_TEXT), "col1")
sql1.BeginTransaction
For i = 1 To 10000
   sql1.ExecNonQuery2("INSERT INTO table1 VALUES(?,?)", _
     Array As Object(i, "value " & i))
Next
sql1.TransactionSuccessful
Make sure to read this tutorial: http://www.b4x.com/android/forum/threads/webapp-concurrent-access-to-sqlite-databases.39904/

- Getting a value from a random row (based on the primary key): >2000 requests per second.
- Same as above. 10% of the requests are INSERT statements: ~700 requests per second.
- 50% of the requests are INSERT statements: ~180 requests per second.
- 100% of the requests are INSERT statements: ~95 requests per second.

Notes:
1. These tests were done on a SSD drive (the MySQL tests were done on a non-SSD drive).
2. During the tests a bug was found in SQL library v1.10 related to concurrent updates of SQLite databases. v1.11 fixes this issue.
3. The results are quite good and show that SQLite can be a good choice for a backend database.
 
Last edited:

luke2012

Well-Known Member
Licensed User
Longtime User
Thank you @Erel ! It's a very good news for me.

The above code run on a B4J desktop app, right ?
 
Last edited:

billzhan

Active Member
Licensed User
Longtime User
FYI luke2012,

I made a test with simulated incoming connection with ab.
SW: WinXp sp3,B4j 2.0 and SQL library v1.10.
HW: Intel T7300 4G SSD pxm5s 128g

The test results are not accurate, with 10%-20% variation.

---------
-n500 -c10 Results:
100% read:1066.67 [#/sec] (mean)
90% read: 864.86 [#/sec] (mean)
50% read:680.85 [#/sec] (mean)
10% read:695.65 [#/sec] (mean)
0% read:727.27 [#/sec] (mean)

---------
-n5000 -c10 Results:
100% read:831.17 [#/sec] (mean)
90% read:831.17 [#/sec] (mean)
50% read:769.23 [#/sec] (mean)
10% read:732.27 [#/sec] (mean)
0% read: 728.93 [#/sec] (mean)

---------
-n5000 -c100 Results:
100% read:694.14 [#/sec] (mean)
90% read:686.70 [#/sec] (mean)
50% read:603.77 [#/sec] (mean)
10% read:576.58 [#/sec] (mean)
0% read:544.22 [#/sec] (mean)




How the test is Done:
1.Simulate incoming connection with ab(apache benchmark), with two parameters, id and p.

1.1 id is the test ID which is used to pass the identify the test.It will be recorded in "errorlog.txt" if any exception.

1.2 p is the percentage of read, an integer 0-100, when p=50 there is 50% that the thread will read a random value from db.

1.3 Write a "test.bat" file under the same path of "ab.exe". -n500 means 500 connections will be sent totally, -c10 means 10 concurrent connections:
B4X:
ab -n500 -c10 "http://192.168.1.100:51042/update?id=1&p=100"  >>testres.txt

2.Run the B4J server at release mode.

3.Run the test.bat, and wait for a moment till the command windows to close.

4.Find in "testres.txt“ file under the same path of "ab.exe", the line "Requests per second: 914.29 [#/sec] (mean) " shows the result.

5.If there is any exception, it will be recorded in "errorlog.txt" under DirApp folder.
 

Attachments

  • b4jslqitetest.zip
    66.8 KB · Views: 1,366
Last edited:
Top