Salut à tous,

Je développe actuellement un programme en vb .net qui opère sur des fichiers texte conséquents. Je réalise un grand nombre de calculs sur les chaînes de caractères (par le biais de for each... next imbriqués les uns dans les autres). J'ai commencé par essayer de tout faire à la volée, en utilisant une combinaison de dictionnaires et de structures. Le souci est vite apparu: j'ai saturé mes 16 Go de Ram en 5mn de traitement en utilisant un fichier d'essai de 20 000 mots alors que je compte traiter des fichiers jusqu'à 300 000 mots.

J'ai donc décidé d'inscrire au fur et à mesure les données dans une base SQLite. Dès mes premières tentatives, j'ai eu une erreur "unable to open database" liée au fait que je réutilisais à chaque requette la même instance de SQLiteConnection.

J'ai donc choisi de réécrire une classe qui gère les lectures écritures SQLite en instanciant sans réfléchir SQLiteConnection à chaque action. Le programme a fonctionné correctement, mais le temps de traitement est passé à plus d'une heure pour les 20 000 mots.

Je viens donc chercher de l'aide pour savoir quelle est la meilleure façon de structurer mes requêtes pour gagner du temps de traitement. Voir ci dessous ma classe de connexion avec en commentaires une estimation à la louche du nombre de requêtes envoyées à la suite:

Code vb.net : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Imports Finisar.SQLite
 
Public Class DB_tools
    Dim ConnectionString1 As String = "Data Source=" & My.Application.Info.DirectoryPath & "\resources\test.db;Version=3;New=True;UTF8Encoding=True;Cache Size=3000;"
    Dim ConnectionString2 As String = "Data Source=" & My.Application.Info.DirectoryPath & "\resources\test.db;Version=3;New=False;UTF8Encoding=True;Cache Size=6000;"
 
    Public Sub New()
    End Sub
 
 'Fonction utilisée une seule fois
Public Function CreateDB() As System.Exception
        Try
            Using c As New SQLiteConnection(ConnectionString1)
                c.Open()
                Dim mySelectQuery As String = "CREATE TABLE 'Words' ( Word VARCHAR(45), Number_of_words INTEGER (4));"
                Dim sqCommand As SQLiteCommand = c.CreateCommand()
                sqCommand.CommandText = mySelectQuery
                sqCommand.ExecuteNonQuery()
                c.Close()
            End Using
            Using c As New SQLiteConnection(ConnectionString2)
                c.Open()
                Dim mySelectQuery As String = "CREATE TABLE 'Sentences' ( Sentence TEXT, Number_of_words INTEGER (4));"
                Dim sqCommand As SQLiteCommand = c.CreateCommand()
                sqCommand.CommandText = mySelectQuery
                sqCommand.ExecuteNonQuery()
                c.Close()
            End Using
            Using c As New SQLiteConnection(ConnectionString2)
                c.Open()
                Dim mySelectQuery As String = "CREATE TABLE 'Paragraphs' (Paragraph TEXT, Number_of_words INTEGER (4));"
                Dim sqCommand As SQLiteCommand = c.CreateCommand()
                sqCommand.CommandText = mySelectQuery
                sqCommand.ExecuteNonQuery()
                c.Close()
            End Using
            Using c As New SQLiteConnection(ConnectionString2)
                c.Open()
                Dim mySelectQuery As String = "CREATE TABLE 'Global' ( Property VARCHAR(45), Value VARCHAR(4));"
                Dim sqCommand As SQLiteCommand = c.CreateCommand()
                sqCommand.CommandText = mySelectQuery
                sqCommand.ExecuteNonQuery()
                c.Close()
                c.Dispose()
 
            End Using
            Return Nothing
        Catch ex As Exception
            Return ex
            MessageBox.Show(ex.ToString)
        End Try
 
    End Function
    Public Function write(ByRef MSG As String) As System.Exception 'Fonction utilisée soit une fois, soit sur une boucle de 3 à 50 itérations
        Try
            Using c As New SQLiteConnection(ConnectionString2)
                c.Open()
                Dim mySelectQuery As String = MSG
                Dim sqCommand As SQLiteCommand = c.CreateCommand()
                sqCommand.CommandText = mySelectQuery
                sqCommand.ExecuteNonQuery()
                c.Close()
                c.Dispose()
 
            End Using
            Return Nothing
        Catch ex As Exception
            Return ex
            MessageBox.Show(ex.ToString)
        End Try
 
 
    End Function
    Public Function Read(ByRef MSG As String) As String 'fonction utilisée une seule fois à chaque passage
        Using c As New SQLiteConnection(ConnectionString2)
 
 
            c.Open()
            Dim mySelectQuery As String = MSG
            Dim sqCommand As SQLiteCommand = c.CreateCommand()
            sqCommand.CommandText = mySelectQuery
            Dim sqReader As SQLiteDataReader = sqCommand.ExecuteReader()
 
            While sqReader.Read()
                Return sqReader.GetString(0)
            End While
            c.Close()
            c.Dispose()
            sqReader.Close()
        End Using
 
 
    End Function
End Class