Android Question Seeking Guidance on Optimizing Database Access for Scaling B4X App

amarnath

Member
Licensed User
Longtime User
I'm currently using B4J with JdbcSQL to connect directly to a remote MySQL database:

B4X:
Public mysql As JdbcSQL
Public driver As String = "com.mysql.jdbc.Driver"
Public jdbcUrl As String = "jdbc:mysql://207.1*.2*.2*:3306/amarnq4g_dairy?useSSL=False&characterEncoding=utf8"
Public Username As String = "amarg_amarnath"
Public Password As String = "Amarnath@@1234"

However, saving data takes over 30 seconds—too slow for my growing user base (projected >1000 clients).

Would switching to RDC (Remote Database Connector) or using a custom API (e.g., api.php) significantly improve performance and scalability?

Given your expertise, which approach would you recommend for a high-performance B4X mobile app serving thousands of users?

Thank you for your time and guidance.
 

hibrid0

Active Member
Licensed User
Longtime User
Check this template ready to use from the master Aeric. Why you don't use the search function? 🤔🤔🤔
Have a lot of examples.

And this is a mod for Jrdc2 for multiple dbs, json answers and more performance.
 
Last edited:
Upvote 0

amarnath

Member
Licensed User
Longtime User
Check this template ready to use from the master Aeric.
Thank you for your patience.
I’ve decided to fully switch to jRDC2—since I have a VPS and want to stay 100% in the B4X ecosystem.

This will help me avoid common pitfalls and move forward smoothly.


Thanks again for all your support!
 
Upvote 0

fungms

Member
I'm currently using B4J with JdbcSQL to connect directly to a remote MySQL database:

B4X:
Public mysql As JdbcSQL
Public driver As String = "com.mysql.jdbc.Driver"
Public jdbcUrl As String = "jdbc:mysql://207.1*.2*.2*:3306/amarnq4g_dairy?useSSL=False&characterEncoding=utf8"
Public Username As String = "amarg_amarnath"
Public Password As String = "Amarnath@@1234"

However, saving data takes over 30 seconds—too slow for my growing user base (projected >1000 clients).

Would switching to RDC (Remote Database Connector) or using a custom API (e.g., api.php) significantly improve performance and scalability?

Given your expertise, which approach would you recommend for a high-performance B4X mobile app serving thousands of users?

Thank you for your time and guidance.
Well, maybe client isn't so important as well optimized queries and indexes. If those two are done, then you can limit records to transfer.

If you joining some tables with many records, please filter to minimum start records in the first table, then join next tables ON indexed columns (the best are ints).

Every column in WHERE clause should be indexed. If you can not index column you should think about change data types.

The fastest indexes are numbers (integers), a little bit dates. The slowest are strings, a specially a long varchars (or blobs).

If query runs slow on server - on client will be slower of course (time for transfer data)
 
Upvote 0

amarnath

Member
Licensed User
Longtime User
Well, maybe client isn't so important as well optimized queries and indexes. If those two are done, then you can limit records to transfer.

If you joining some tables with many records, please filter to minimum start records in the first table, then join next tables ON indexed columns (the best are ints).

Every column in WHERE clause should be indexed. If you can not index column you should think about change data types.

The fastest indexes are numbers (integers), a little bit dates. The slowest are strings, a specially a long varchars (or blobs).

If query runs slow on server - on client will be slower of course (time for transfer data)
I’m moving to jRDC2 and rewriting all my database queries using it.
Thanks for the advice—I’ll make sure every query is optimized with proper indexes (especially on integer columns) and minimal data transfer.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
I suggest using a RESTful API. This will keep the data layers separate from your client apps, which can be developed in other languages. In other words, your applications can be written in Java, JavaScript, .NET, etc., and still access your data.

Most web hosting providers come with Node and Apache pre-installed, giving you the option to choose what to use for your RESTful API.

Example:
Node + Express (https://expressjs.com/)
Apache + PHP + Slim (https://www.slimframework.com/)


Both are easy to implement and support multiple database types (Oracle, MySQL, MariaDB, SQL Server, etc.).

Note:

One observation is that both frameworks handle security and data transfer layers.

There are other RESTful APIs that are simpler or that you can develop yourself, but they only transfer and retrieve data, without security layers, and these frameworks include them.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
This can help you make requests to your RESTful API from your B4X client apps.

 
Upvote 0

Bladimir Silva Toro

Active Member
Licensed User
Longtime User
Hello @amarnath

Hi, I also recommend using jRDC2. I have at least 100 users connected to an MS SQL Server 2019 database and it works perfectly. I have a mobile invoicing app in B4A and a point-of-sale application for Windows desktop in VB.NET.

Note: jRDC2 uses HikariCP as its connection pool library, and the key parameter is:

MaximumPoolSize → the maximum number of simultaneous connections to the database.

If you use 50 simultaneous connections, you could use more than 500 users.

The server for MySQL and jRDC2 should have this hardware:

16 vCPUs, 32 GB RAM, NVMe SSD, 64-bit Linux

After this, I don't know how much the performance would improve for saving data; it shouldn't take 20, 30, or 50 seconds.

I recommend testing with jRDC2 initially, as it's easier to do and not as complex to implement.
 
Upvote 0

amarnath

Member
Licensed User
Longtime User
Hello @amarnath

Hi, I also recommend using jRDC2. I have at least 100 users connected to an MS SQL Server 2019 database and it works perfectly. I have a mobile invoicing app in B4A and a point-of-sale application for Windows desktop in VB.NET.

Note: jRDC2 uses HikariCP as its connection pool library, and the key parameter is:

MaximumPoolSize → the maximum number of simultaneous connections to the database.

If you use 50 simultaneous connections, you could use more than 500 users.

The server for MySQL and jRDC2 should have this hardware:

16 vCPUs, 32 GB RAM, NVMe SSD, 64-bit Linux

After this, I don't know how much the performance would improve for saving data; it shouldn't take 20, 30, or 50 seconds.

I recommend testing with jRDC2 initially, as it's easier to do and not as complex to implement.
Thank you for the detailed advice!


I’ve already started migrating everything to jRDC2 and rewriting all my queries accordingly.
It’s reassuring to know it handles 100+ users smoothly—that gives me real confidence.


I’m not an expert, so I’d really appreciate your support as I finalize the migration. I’m rewriting every query in jRDC2 format and aim to complete the full app within one month.


If I run into issues with query structure, performance, or deployment on my VPS, I may reach out again for guidance—thank you in advance for your help!


Thanks again!
 
Upvote 0
Top