Browse Source

Modified to use Prepared Statement, and add setup file for a benchmark of 'thread' MPM.

AOYAMA Kazuharu 11 years ago
parent
commit
3a2b6ff573

+ 24 - 1
treefrog/benchmark_config

@@ -20,7 +20,30 @@
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
-      "display_name": "treefrog",
+      "display_name": "treefrog-hybrid",
+      "notes": "",
+      "versus": ""
+    },
+    "thread": {
+      "setup_file": "setup-thread",
+      "json_url": "/json/json",
+      "db_url": "/world/random",
+      "query_url": "/world/queries/",
+      "fortune_url": "/fortune/index",
+      "update_url": "/world/updates/",
+      "plaintext_url": "/world/plain",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "MySQL",
+      "framework": "treefrog",
+      "language": "C++",
+      "orm": "Micro",
+      "platform": "Treefrog",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "treefrog-thread",
       "notes": "",
       "versus": ""
     }

+ 12 - 8
treefrog/config/application.ini

@@ -105,8 +105,12 @@ Session.CsrfProtectionKey=_csrfId
 ## MPM Thread section
 ##
 
-# Maximum number of server threads allowed to start
-MPM.thread.MaxServers=512
+# Number of application server processes to be started.
+MPM.thread.MaxAppServers=10
+
+# Maximum number of action threads allowed to start simultaneously
+# per server process.
+MPM.thread.MaxThreadsPerAppServer=100
 
 ##
 ## MPM Prefork section
@@ -125,12 +129,12 @@ MPM.prefork.SpareServers=5
 ## MPM Hybrid section
 ##
 
-# Number of server processes to be started.
-# Specify a value of range from 1 to the number of processor.
-MPM.hybrid.MaxServers=8
+# Number of application server processes to be started.
+MPM.hybrid.MaxAppServers=10
 
-# Maximum number of worker threads allowed to start per server process.
-MPM.hybrid.MaxWorkersPerServer=128
+# Maximum number of worker threads allowed to start simultaneously
+# per server process.
+MPM.hybrid.MaxWorkersPerAppServer=100
 
 ##
 ## SystemLog settings
@@ -159,7 +163,7 @@ SystemLog.DateTimeFormat="yyyy-MM-dd hh:mm:ss"
 ##
 
 # Specify the access log file name.
-AccessLog.FilePath=/dev/null
+AccessLog.FilePath=
 
 # Specify the layout of the access log.
 #  %h : Remote host

+ 7 - 3
treefrog/controllers/applicationcontroller.cpp

@@ -22,16 +22,19 @@ bool ApplicationController::preFilter()
 
 QString ApplicationController::jsonEncode(const QVariantMap &obj)
 {
+    const QString JSON_OBJ_INT("\"%1\":%2, ");
+    const QString JSON_OBJ_STR("\"%1\":\"%2\", ");
     QString ret("{");
+
     for (QMap<QString, QVariant>::const_iterator i = obj.begin(); i != obj.end(); ++i) {
         switch (i.value().type()) {
         case QVariant::UInt:
         case QVariant::Int:
-            ret += QString("\"%1\":%2, ").arg(i.key()).arg(i.value().toInt());
+            ret += JSON_OBJ_INT.arg(i.key()).arg(i.value().toInt());
             break;
         default:
-            ret += QString("\"%1\":\"%2\", ").arg(i.key()).arg(i.value().toString());
-            break; 
+            ret += JSON_OBJ_STR.arg(i.key()).arg(i.value().toString());
+            break;
         }
     }
     ret.chop(2);
@@ -42,6 +45,7 @@ QString ApplicationController::jsonEncode(const QVariantMap &obj)
 QString ApplicationController::jsonEncode(const QList<QVariantMap> &lst)
 {
     QString ret("[");
+
     for (QListIterator<QVariantMap> it(lst); it.hasNext(); ) {
         ret += jsonEncode(it.next());
         ret += QLatin1String(", ");

+ 1 - 1
treefrog/controllers/applicationcontroller.h

@@ -21,7 +21,7 @@ public slots:
     void staticInitialize();
 
 protected:
-    virtual bool preFilter();    
+    virtual bool preFilter();
 };
 
 T_DECLARE_CONTROLLER(ApplicationController, applicationcontroller)

+ 6 - 0
treefrog/controllers/fortunecontroller.cpp

@@ -1,6 +1,10 @@
 #include "fortunecontroller.h"
 #include "fortune.h"
 
+static bool caseSensitiveLessThan(const Fortune &f1, const Fortune &f2)
+{
+    return f1.message() < f2.message();
+}
 
 FortuneController::FortuneController(const FortuneController &)
     : ApplicationController()
@@ -9,6 +13,8 @@ FortuneController::FortuneController(const FortuneController &)
 void FortuneController::index()
 {
     QList<Fortune> fortuneList = Fortune::getAll();
+    // Sort
+    qSort(fortuneList.begin(), fortuneList.end(), caseSensitiveLessThan);
     texport(fortuneList);
     render();
 }

+ 5 - 3
treefrog/controllers/worldcontroller.cpp

@@ -29,10 +29,10 @@ void WorldController::queries(const QString &num)
 {
     QList<QVariantMap> worlds;
     int d = num.toInt();
+
     for (int i = 0; i < d; ++i) {
         int id = Tf::random(9999) + 1;
-        World world = World::get(id);
-        worlds << world.toVariantMap();
+        worlds << World::get(id).toVariantMap();
     }
     setContentType("application/json; charset=UTF-8");
     renderText(jsonEncode(worlds), false);
@@ -124,9 +124,11 @@ void WorldController::updates(const QString &num)
 {
     QList<QVariantMap> worlds;
     int d = num.toInt();
+    World world;
+
     for (int i = 0; i < d; ++i) {
         int id = Tf::random(9999) + 1;
-        World world = World::get(id);
+        world = World::get(id);
         world.setRandomNumber( Tf::random(9999) + 1 );
         world.update();
 	worlds << world.toVariantMap();

+ 19 - 2
treefrog/models/fortune.cpp

@@ -4,7 +4,9 @@
 
 Fortune::Fortune()
     : TAbstractModel(), d(new FortuneObject)
-{ }
+{
+    d->id = 0;
+}
 
 Fortune::Fortune(const Fortune &other)
     : TAbstractModel(), d(new FortuneObject(*other.d))
@@ -67,9 +69,24 @@ Fortune Fortune::get(uint id)
     return Fortune(mapper.findByPrimaryKey(id));
 }
 
+int Fortune::count()
+{
+    TSqlORMapper<FortuneObject> mapper;
+    return mapper.findCount();
+}
+
 QList<Fortune> Fortune::getAll()
 {
-    return tfGetModelListByCriteria<Fortune, FortuneObject>(TCriteria());
+    TSqlQueryORMapper<FortuneObject> mapper;
+    mapper.prepare("SELECT * from Fortune");
+
+    QList<Fortune> fortunes;
+    if (mapper.exec()) {
+        while (mapper.next()) {
+            fortunes << Fortune(mapper.value());
+        }
+    }
+    return fortunes;
 }
 
 TModelObject *Fortune::modelData()

+ 6 - 0
treefrog/models/fortune.h

@@ -25,9 +25,15 @@ public:
     void setMessage(const QString &message);
     Fortune &operator=(const Fortune &other);
 
+    bool create() { return TAbstractModel::create(); }
+    bool update() { return TAbstractModel::update(); }
+    bool save()   { return TAbstractModel::save(); }
+    bool remove() { return TAbstractModel::remove(); }
+
     static Fortune create(const QString &message);
     static Fortune create(const QVariantMap &values);
     static Fortune get(uint id);
+    static int count();
     static QList<Fortune> getAll();
 
 private:

+ 18 - 1
treefrog/models/world.cpp

@@ -5,6 +5,7 @@
 World::World()
     : TAbstractModel(), d(new WorldObject)
 {
+    d->id = 0;
     d->randomNumber = 0;
 }
 
@@ -43,6 +44,14 @@ World &World::operator=(const World &other)
     return *this;
 }
 
+bool World::update()
+{
+    TSqlQueryORMapper<WorldObject> mapper;
+    mapper.prepare("UPDATE World SET randomNumber=? WHERE id=?");
+    mapper.addBind(randomNumber()).addBind(id());
+    return mapper.exec();
+}
+
 World World::create(int randomNumber)
 {
     WorldObject obj;
@@ -64,9 +73,17 @@ World World::create(const QVariantMap &values)
 }
 
 World World::get(uint id)
+{
+    TSqlQueryORMapper<WorldObject> mapper;
+    mapper.prepare("SELECT * from World WHERE id=?");
+    mapper.addBind(id);
+    return World(mapper.execFirst());
+}
+
+int World::count()
 {
     TSqlORMapper<WorldObject> mapper;
-    return World(mapper.findByPrimaryKey(id));
+    return mapper.findCount();
 }
 
 QList<World> World::getAll()

+ 6 - 0
treefrog/models/world.h

@@ -25,9 +25,15 @@ public:
     void setRandomNumber(int randomNumber);
     World &operator=(const World &other);
 
+    bool create() { return TAbstractModel::create(); }
+    bool update();
+    bool save()   { return TAbstractModel::save(); }
+    bool remove() { return TAbstractModel::remove(); }
+
     static World create(int randomNumber);
     static World create(const QVariantMap &values);
     static World get(uint id);
+    static int count();
     static QList<World> getAll();
 
 private:

+ 1 - 0
treefrog/setup.py

@@ -11,6 +11,7 @@ home = expanduser("~")
 ##############
 def start(args, logfile, errfile):
   setup_util.replace_text("treefrog/config/database.ini", "HostName=.*", "HostName=" + args.database_host)
+  setup_util.replace_text("treefrog/config/application.ini", "MultiProcessingModule=.*", "MultiProcessingModule=hybrid")
 
   # 1. Generate Makefile
   # 2. Compile applicaton