I'm using as lot of small SQLite-databases with the keyvaluestore2-class in my project and it works fine in normal mode. But on every stress test of my messenger-app, I always get sqlite-exceptions:
I think, that i don't use the databases in the right way. I have some questions about it to understand the reasons for the exceptions. Hope, someone could help me:
1.
I'm saving the members of the chats in small sqlite-databases. Every time, when a client sends a message to the server, the server reads the keyvaluestore in a local variabel and reads out the information to which member the message should send to. I use the following code (greatly simplifies):
If there are a lot of messages, the code-modul with the Push-sub is called a lot of times shortly after each other. I think, that it is unproblematic because each time the database is stored in a lokal variable. Is that correct or is there a problem?
2.
The small databases are downloaded by the clients to get also the informations about the members of a chat. If I set the wal-mode to true, do I have to download all 3 database-files (file, file-shm and file-wal) or are all relevant informations in the main-file of the kvs?
3.
I think, that the main problem of my app is the use of the follwing code (greatly simplifies):
The DeviceDownload-KVS are small databases for each user of the messenger, in which all messages which are send to will be saved to sync the client later with the server. It is important, that the files are small to make a fast synchronization with the server after starting the app. If the message is already on the client, the key will be removed out of the DeviceDownload-KVS. If there are a lot of messages, devicedownload for each user will be initialized a lot of times and the server writes to. I think, that this is the main problem and the reason for the exceptions above. What will be a realitic solution for this kind of problem without rewriting the whole app?
We use for each unit of 100 to 130 peoble one server. I think that there are no great requirements to the system....
Thanks for any help...
B4X:
ERROR - In Modul FileServer, Sub Handle: java.sql.SQLException: [SQLITE_IOERR] Some kind of disk I/O error occured (disk I/O error)
ERROR - In Modul IOSPushFirebase, Sub SendMessage: java.sql.SQLException: [SQLITE_CANTOPEN] Unable to open the database file (out of memory)
FATAL - In Modul Main, Sub AppStart Code 2: java.sql.SQLException: [SQLITE_CANTOPEN] Unable to open then database file (out of memory)
ERROR - In Modul IOSPushFirebase, Sub SendMessage: java.sql.SQLException: [SQLITE_IOERR] Some kind of disk I/O error occured (disk I/O error)
I think, that i don't use the databases in the right way. I have some questions about it to understand the reasons for the exceptions. Hope, someone could help me:
1.
I'm saving the members of the chats in small sqlite-databases. Every time, when a client sends a message to the server, the server reads the keyvaluestore in a local variabel and reads out the information to which member the message should send to. I use the following code (greatly simplifies):
B4X:
Sub Push(msg As Map)
Dim iosTokens As List
iosTokens.Initialize
Dim Kontaktgruppe As KeyValueStore2
Kontaktgruppe.Initialize(File.DirApp, "Konferenzen/" & "KG_" & msg.Get("konferenz") & ".db", False)
For Each key As String In Kontaktgruppe.ListKeys
Dim ID As String
ID=Kontaktgruppe.Get(key)
iosTokens.Add(ID)
Next
If iosTokens.Size > 0 Then CallSubDelayed3(iOSPushFirebase, "SendMessageTo", iosTokens, msg)
End Sub
If there are a lot of messages, the code-modul with the Push-sub is called a lot of times shortly after each other. I think, that it is unproblematic because each time the database is stored in a lokal variable. Is that correct or is there a problem?
2.
The small databases are downloaded by the clients to get also the informations about the members of a chat. If I set the wal-mode to true, do I have to download all 3 database-files (file, file-shm and file-wal) or are all relevant informations in the main-file of the kvs?
3.
I think, that the main problem of my app is the use of the follwing code (greatly simplifies):
B4X:
Private Sub SendMessage(Devices As List, msg As Map)
.....
Dim DeviceDownload As KeyValueStore2
For i=0 To Devices.Size-1
Dim LE As List = Kontakte.Get(Devices.Get(i))
DeviceDownload.Initialize(File.DirApp, "Download_/" & LE.Get(0) & ".db", False)
Dim FilesMap As Map
FilesMap.Initialize
If DeviceDownload.ContainsKey(Name) Then FilesMap=DeviceDownload.Get(Name)
Dim Dateiname As String = msg.Get("filename")
FilesMap.Put(Dateiname, msg.Get("daten"))
DeviceDownload.Put(Name, FilesMap)
Next
....
Dim jg As JSONGenerator
jg.Initialize(m)
Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
Job.GetRequest.SetContentType("application/json;charset=UTF-8")
Job.GetRequest.SetHeader("Authorization", "key=" & FirebasePushApiKey)
End Sub
The DeviceDownload-KVS are small databases for each user of the messenger, in which all messages which are send to will be saved to sync the client later with the server. It is important, that the files are small to make a fast synchronization with the server after starting the app. If the message is already on the client, the key will be removed out of the DeviceDownload-KVS. If there are a lot of messages, devicedownload for each user will be initialized a lot of times and the server writes to. I think, that this is the main problem and the reason for the exceptions above. What will be a realitic solution for this kind of problem without rewriting the whole app?
We use for each unit of 100 to 130 peoble one server. I think that there are no great requirements to the system....
Thanks for any help...