main.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <stdio.h>
  2. #include "connectionManager.hpp"
  3. ConnectionManager connectionManager;
  4. Module mod = Module::dummyBigModule;
  5. size_t s=0, f=0, r=0;
  6. std::mutex statsLk;
  7. void work() {
  8. auto worker = connectionManager.createWorker(mod, 1000);
  9. worker->setJobTimeout(milliseconds(1000));
  10. worker->setRetryCount(10);
  11. worker->setDoneCallback([worker](){
  12. auto jobs = worker->getJobList();
  13. std::unique_lock<std::mutex> lk(statsLk);
  14. for(size_t i=0; i<jobs->getJobCount(); i++) {
  15. auto job = jobs->getJob(i);
  16. if(job->getState() == JobState::finished) {
  17. s++;
  18. } else if(job->getState() == JobState::failed) {
  19. f++;
  20. } else {
  21. printf("job %08X: invalid state %d\n", job->getJobId(), (int)job->getState());
  22. }
  23. r += job->getSendCounter() - 1;
  24. }
  25. });
  26. {
  27. auto jobs = worker->getJobList();
  28. for(size_t i=0; i<jobs->getJobCount(); i++) {
  29. auto job = jobs->getJob(i);
  30. static int num=0;
  31. job->setPayload(0, num);
  32. job->setPayload(1, num);
  33. job->setPayload(2, num);
  34. job->setPayload(3, num++);
  35. job->setReady();
  36. }
  37. }
  38. worker->startAsync();
  39. }
  40. int main(void)
  41. {
  42. puts("This is a shared library test...");
  43. connectionManager.addFPGA("192.168.1.33", 1234);
  44. connectionManager.addFPGA("192.168.1.34", 1234);
  45. connectionManager.addFPGA("192.168.1.35", 1234);
  46. connectionManager.setSendDelay(microseconds(50));
  47. connectionManager.start();
  48. int workNum = 10000;
  49. int n=1;
  50. while(workNum > 0 || connectionManager.getWorkerCount() > 0) {
  51. std::this_thread::sleep_for(milliseconds(300));
  52. connectionManager.removeFinishedWorkers();
  53. while(workNum > 0 && connectionManager.getWorkerCount() < 8) {
  54. workNum--;
  55. work();
  56. }
  57. std::unique_lock<std::mutex> lk(statsLk);
  58. printf("work: %2d worker: %2lu failed: %12lu, successful: %12lu, retries: %12lu %4lu MBit/s\n", workNum, connectionManager.getWorkerCount(), f, s, r, s*(moduleSendPayloadLength[mod]+4)*4*10*8/1024/1024/3/(n++));
  59. }
  60. return 0;
  61. }