summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--Makefile.mingw328
-rw-r--r--empty0
-rw-r--r--heavy_loader.cpp138
4 files changed, 156 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..c1f1b94
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,10 @@
+all:
+ g++ -c *.cpp -I/usr/include -O2 -pipe -fomit-frame-pointer -march=core2
+ #g++ -c *.cpp -I/usr/include -g3 -ggdb -pipe
+ g++ -o loader *.o -lboost_thread-mt -lboost_random-mt -lcurl -Wl,-O1 -s
+ #g++ -o loader *.o -lboost_thread-mt -lboost_random-mt -lcurl
+clean:
+ rm *.o
+clean-all:
+ rm *.o loader
+
diff --git a/Makefile.mingw32 b/Makefile.mingw32
new file mode 100644
index 0000000..a780243
--- /dev/null
+++ b/Makefile.mingw32
@@ -0,0 +1,8 @@
+all:
+ i686-pc-mingw32-g++ -c *.cpp -I/home/sss/temp/mingw/usr/i686-pc-mingw32/include -O2 -pipe -fomit-frame-pointer -march=i686 -DWIN32 -D_WIN32 -DBOOST_THREAD_USE_LIB
+ i686-pc-mingw32-g++ -o loader.exe *.o -lssl -lcrypto -lwldap32 -lcurl -lidn -lintl -liconv -lssh2 -lwldap32 -lz -lgnutls -lnettle -lhogweed -lgmp -lz -lssh2 -lgcrypt -lgpg-error -lboost_system-mt -lboost_date_time-mt -lboost_thread_win32-mt -lboost_random-mt -lboost_filesystem-mt -lmswsock -lws2_32 -lgdi32 -lz -Wl,-O1 -s
+clean:
+ rm *.o
+clean-all:
+ rm *.o loader.exe
+
diff --git a/empty b/empty
deleted file mode 100644
index e69de29..0000000
--- a/empty
+++ /dev/null
diff --git a/heavy_loader.cpp b/heavy_loader.cpp
new file mode 100644
index 0000000..323f470
--- /dev/null
+++ b/heavy_loader.cpp
@@ -0,0 +1,138 @@
+#include <boost/thread.hpp>
+#include <boost/random.hpp>
+#include <boost/nondet_random.hpp>
+#include <list>
+#include <curl/curl.h>
+
+
+
+
+size_t failed_threads = 0, success_threads = 0;
+
+
+
+size_t curl_data_callback(void *contents, size_t size, size_t nmemb, void *userp)
+{
+ return size * nmemb;
+}
+
+
+std::string get_random(int length)
+{
+ std::string chars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
+ std::string data;
+ try{
+ boost::random_device rng;
+ boost::variate_generator<boost::random_device&, boost::uniform_int<> > gen(rng, boost::uniform_int<>(0, chars.length()-1));
+ for(int i = 0; i < length; ++i)
+ data += chars[gen()];
+ }
+ catch(const std::exception &e)
+ {
+ data.clear();
+ for(int i = 0; i < length; ++i)
+ data += "a";
+ return data;
+ }
+ return data;
+}
+
+class curl_test
+{
+public:
+ curl_test(const char* d): s(d), finished(false), thr(NULL){}
+ void start()
+ {
+ thr = new boost::thread(boost::bind(curl_test::test, s, this));
+ }
+ ~curl_test()
+ {
+ delete thr;
+ }
+ static void test(const std::string &s, curl_test *c)
+ {
+ CURL *curl = NULL;
+ curl = curl_easy_init();
+ if(!curl)
+ return;
+ std::string url = s;
+ url += "/";
+ url += get_random(5);
+ url += "/";
+ url += get_random(3);
+ curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
+ curl_easy_setopt(curl, CURLOPT_USERAGENT, "tuk-tuk/0.1");
+ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2);
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, 2);
+ //curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1);
+ curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &curl_data_callback);
+
+ time_t start = time(0);
+
+ CURLcode error = curl_easy_perform(curl);
+
+ if(!error)
+ success_threads++;
+
+ double t = time(0) - start;
+
+ curl_easy_cleanup(curl);
+ c->finished = true;
+
+ }
+ const std::string s;
+ bool finished;
+private:
+ boost::thread *thr;
+};
+
+std::list<curl_test> threads;
+
+void threads_count()
+{
+ while(true)
+ {
+ std::cout<<"Runninng: "<<threads.size()<<" threads"<<std::endl;
+ if(failed_threads)
+ std::cout<<"Failed to start: "<<failed_threads<<" threads"<<std::endl;
+ std::cout<<"Correct server reply recieved in "<<success_threads<<" threads"<<std::endl;
+ boost::this_thread::sleep(boost::posix_time::seconds(3));
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ if(argc == 3)
+ {
+ new boost::thread(boost::bind(threads_count));
+ int max_threads = atoi(argv[2]);
+ for(;;)
+ {
+ while(threads.size() >= max_threads)
+ {
+ for(std::list<curl_test>::iterator i = threads.begin(), end = threads.end(); i != end; ++i)
+ {
+ if(i->finished)
+ {
+ threads.erase(i);
+ i = threads.begin(), end = threads.end();
+ }
+ }
+ boost::this_thread::sleep(boost::posix_time::milliseconds(10));
+ }
+ try{
+ threads.push_back(curl_test(argv[1]));
+ threads.back().start();
+ }
+ catch(const std::exception &e)
+ {
+ failed_threads++;
+ }
+ }
+ }
+ else
+ std::cout<<"usage: "<<argv[0]<<" base_url threads_count"<<std::endl;
+ return 0;
+}